阿里的JSONObject 对象转化为Map对象
//json对象转为map
public Map<String,Object> JsonToMap(JSONObject json){
System.out.println("********************转Map对象******************"+json);
Map<String, Object> data =new HashMap<>();
//循环转换
System.out.println("***********************json*****************"+json);
Iterator it =json.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) it.next();
data.put(entry.getKey(), entry.getValue());
}
System.out.println("map对象:"+data.toString());
return data;
}
本文介绍了如何将JSONObject对象转换为Java Map对象,通过遍历JSONObject的entrySet,逐个添加键值对实现。适合理解JSON处理和基础数据结构转换。
7993

被折叠的 条评论
为什么被折叠?



