JSONObject 转String 不去除null

2019-03-21  本文已影响0人  DH东海
JSONObject.toJSONString(JSONObject对象, SerializerFeature.WriteMapNullValue)

代码

JSONObject jsonObject = new JSONObject();
        Map<String, Object> map =new HashMap<String, Object>();
        map.put("A", null);
        jsonObject.put("AA", map);
        System.out.println("toString:"+ jsonObject.toString());;
        System.out.println("WriteMapNullValue:"+ JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));

输出

toString:{"AA":{}}
WriteMapNullValue:{"AA":{"A":null}}
上一篇 下一篇

猜你喜欢

热点阅读