alibaba的JSON.toString会把值为null的字段去掉,谨记
alibaba的JSON.toString会把值为null的字段去掉,谨记
Map<String,Object> map = new HashMap<>(); map.put("a", "1"); map.put("b", "2"); map.put("c", null); String jsonString = JSON.toJSONString(map); System.out.println(jsonString); 结果:{"a":"1","b":"2"} Map<String,Object> map = new HashMap<>(); map.put("a", "1"); map.put("b", "2"); map.put("c", ""); String jsonString = JSON.toJSONString(map); System.out.println(jsonString); 结果:{"a":"1","b":"2","c":""}