对象转JSONObject——字段空值不显示处理办法
2021-07-21 本文已影响0人
蜻蜓队长家长
一、引包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.71</version>
</dependency>
二、使用toJSONString()
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
String s = JSONObject.toJSONString(对象,SerializerFeature.WriteMapNullValue);