加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FastJson返回值为空时key丢失

发布时间:2020-12-16 18:56:47 所属栏目:百科 来源:网络整理
导读:FastJson返回值为空时key丢失 使用以下代码解决: // ====================== public static final String toJSONString(Object object) { return JSON.toJSONString(object,SerializerFeature.WriteMapNullValue,SerializerFeature.DisableCircularReferenc

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.52php.cn/article/p-puoezahk-bgb.html
  • http://generalthink.com/2015/11/15/fastjson-serializerFeature/
  • http://www.52php.cn/article/p-avoimhfz-ek.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读