目前使用的是fastjson,遇到了这样的json串:
"panel": {
"8": {
"112": 1
},
"11": {
"147": 2
}
}
其中数字的key都是动态的,而且需要我获取到key用于其他地方做参数。如何解析?
遍历获取Key和Value,demo如下:
LinkedHashMap<String, String> jsonMap = JSON.parseObject(jsonStr, new TypeReference<LinkedHashMap<String, String>>(){});
for (Map.Entry<String, String> entry : jsonMap.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}