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

 

posted @ 2018-06-11 17:56  jwcc  阅读(5404)  评论(0编辑  收藏  举报