FastJson返回值为空时key丢失
使用以下代码解决:
// ====================== public static final String toJSONString(Object object) { return JSON.toJSONString(object,SerializerFeature.WriteMapNullValue,SerializerFeature.DisableCircularReferenceDetect); }
Map < String,Object > jsonMap = new HashMap< String,Object>();<br /> jsonMap.put("a",1);<br /> jsonMap.put("b","");<br /> jsonMap.put("c",null);<br /> jsonMap.put("d","huaqinwang.com");<br /> String str = JSONObject.toJSONString(jsonMap);<br /> System.out.println("没有经过特殊处理的json输出:"+str);<br /> //输出结果:{"a":1,"b":"",d:"huaqinwang.com"}<br /> System.out.println("经过特殊处理的json输出:"+JSONAdvance.toJSONString(jsonMap));<br /> // 输出 经过特殊处理的json输出:{"a":1,"c":null,"d":"huaqinwang.com"}<br />
参考网址
- http://borglee.iteye.com/blog/2047688
- http://www.jb51.cc/article/p-puoezahk-bgb.html
- http://generalthink.com/2015/11/15/fastjson-serializerFeature/
- http://www.jb51.cc/article/p-avoimhfz-ek.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。