fastJSON返回全字段json串

从数据库中取出的值封装到对象中,有的属性为空,fastJSON会忽略掉为空的属性,现在要将为空的属性也在json串中

最终达到这样的要求:

{
    "data": {
        "total": 1,
        "type": "0",
        "items": [
            {
                "id": "213",
                "name": null,
                "sex": null,
            }
        ],
        "key": "213"
    },
    "rtnMsg": "success",
    "rtnCode": "200"
}

jar:fastjson-1.2.32.jar

解决方法:

String result =JSON.toJSONString(list,SerializerFeature.WriteMapNullValue);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章