java遍历json
程序员文章站
2024-02-26 11:10:46
...
1、paramMap为jsonString
Set<String> keys = paramMap.keySet();
Iterator<String> iterator = keys.iterator();
while (iterator.hasNext()){
String key = iterator.next();
log.info("key = {}",key);
log.info("value = {}",paramMap.get(key));
}
2、JSONObject jsonObject = new JSONObject(jsonString);然后用Iterator迭代器遍历取值,建议用反射机制解析到封装好的对象中
JSONObject jsonObject = new JSONObject(jsonString); Iterator iterator = jsonObject.keys(); while(iterator.hasNext()){ key = (String) iterator.next(); value = jsonObject.getString(key); }
2来源于点击打开链接