Json与List之间的相互转换

谷歌的Gson.jar:

//list转换为json
Gson gson = new Gson();  
List persons = new ArrayList();  
String str = gson.toJson(persons); 
//json转换为list
Gson gson = new Gson();  
List persons = gson.fromJson(str, new TypeToken>(){}.getType()); 

阿里的fastJson.jar:

//list转换为json
List list = new ArrayList();
String str=JSON.toJSON(list).toString();
//json转换为list
List list = new ArrayList();  
list = JSONObject.parseArray(jasonArray, Person.class);  

 

原文地址:https://blog.csdn.net/demonliuhui/article/details/52949079

你可能感兴趣的:(Json与List之间的相互转换)