Json與List的相互轉換


谷歌的Gson.jar:

//list轉換為json

Gson gson = new Gson();

List<Person> persons = new ArrayList<Person>();

String str = gson.toJson(persons);

 

//json轉換為list

Gson gson = new Gson();

List<Person> persons = gson.fromJson(str, new TypeToken<List<Person>>(){}.getType());

 

 

阿里的fastJson.jar:

//list轉換為json

List<CustPhone> list = new ArrayList<CustPhone>();

String str=JSON.toJSON(list).toString();

 

//json轉換為list

List<Person> list = new ArrayList<Person>();

list = JSONObject.parseArray(jasonArray, Person.class);

 

參考: 

http://blog.csdn.net/demonliuhui/article/details/52949079
http://blog.csdn.net/qxs965266509/article/details/42774691 
http://huyizizhen.iteye.com/blog/1453621 
http://blog.csdn.net/u010797575/article/details/43304981 
http://blog.csdn.net/paincupid/article/details/51221391

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM