JAVA之Map和JSONObject互转
show me code:
map2jsonObject
private JSONObject toJsonObj(Map<String, Object> map, JSONObject resultJson) {
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
resultJson.put(key, map.get(key));
}
return resultJson;
}
jsonObject2hashMap:
JSONObject object = new JSONObject();
object.put("param", "1");
HashMap<String, String> map = JSONObject.parseObject(object.toString(), HashMap.class);
System.out.println(map);
参考:https://zhidao.baidu.com/question/438987955236829444.html