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}}