JAVA之Map和JSONObject互转

                                  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

https://www.cnblogs.com/hjy1017/p/6755798.html

发布了81 篇原创文章 · 获赞 129 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/u013185349/article/details/105517330