从数据库中取出的值封装到对象中,有的属性为空,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);