直接上代码
public static void main(String[] args) throws Exception {
Map<String,Object> map = new HashMap<>();
map.put("1","!1");
map.put("2",null);
map.put("3",map.get("4"));
System.out.println("json"+ JSON.toJSONString(map,SerializerFeature.WRITE_MAP_NULL_FEATURES, SerializerFeature.QuoteFieldNames));
System.out.println("json"+JSONObject.toJSONString(map));
}
输出结果:
json{"1":"!1","2":null,"3":null}
json{"1":"!1"}