<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.68</version>
</dependency>
首先引入相關jar包,
假設有一個實體類User
public class User{ private int id; private String name; }
然后通過fastJson進行類型轉換
public static void main(String[] args){ String userString = "{"id":1,"name","xsl"}"; JSONObject userJson = JSONObject.parseObject(userString); User user = JSON.toJavaObject(userJson,User.class); }
