從數據庫中取出的值封裝到對象中,有的屬性爲空,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);