Gson是google開發的一個開源Json解析庫,使用十分的方便,在maven當中導入的方式爲:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
其中2.8.2爲版本號,最新版本以及源碼可以在官方的github上查看:https://github.com/google/gson
這裏給出最簡單的Gson的使用方法:
Object obj = new Object();
//Object轉Json字符串
String obstr = new Gson().toJson(object);
//Json字符串轉Object
Object object = new Gson().fromJson(obstr);