fastjson2 的简单使用
导包
随便挑个版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.25</version>
</dependency>
使用
单个对象
String str = JSON.toJSONString(student);//对象-> json
? = JSON.parseObject(str,目标class);//json ->对象
集合,map等
String str = JSON.toJSONString(students);
? = JSON.parse(str,目标class);//json ->集合
JSONArray,JSONObject都是实现了JSON接口的,一般转json都只是转成单个的JSONObject,很少会转为JSONArray(JSONObject数组)。
标签:fastjson2,对象,JSONObject,json,JSON,str,互转 From: https://www.cnblogs.com/LIang2003/p/18244337