4

fastjson 美化输出 JSONObject 和 JSONArray

 2 years ago
source link: https://hellodk.cn/post/830
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

fastjson 美化输出 JSONObject 和 JSONArray

pom.xml 引入 fastjson

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.30</version>
</dependency>

想要输出/打印的是一个 JSONObjectJSONArray。我们假设对象名字是 aaa,那么要想美化输出这个对象,可以这么写

String pretty = JSON.toJSONString(aaa, SerializerFeature.PrettyFormat,
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteDateUseDateFormat);
System.out.println(pretty);

之后打印出来的 pretty 对象就是美化后的 aaa (json 对象或 json 数组)。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK