java json字串轉list
阿新 • • 發佈:2018-11-15
json字串轉list
maven引入jar
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
jar下載地址 gson2.8.2
https://download.csdn.net/download/qq_34874784/10715278
程式碼
public static void main(String[] args) {
String jsonList="[{'id':'1','username':'張三'},"+
"{'id':'2','username':'李四'},"+
"{'id':'3','username':'王五'}]";
Gson gson1=new Gson();
List<Map> list= gson1.fromJson(jsonList, new TypeToken<List<Map>>() {}.getType());
System.out.println(list);
}