JSONObject,JSONArray 与 bean 的转化

json字符串转换为bean对象

String json = "{name:'hello',age:'12'}";

Muser user = (Muser) JSONObject.toBean(json, Muser.class);

 

jsonArray字符串转换为 List实例对象

String response = "[{name:'hello',age:'12'},{name:'hello',age:'12'}]";

JSONArray userArray = JSONArray.fromObject(response);

List<Muser> userList = (List<Muser>) JSONArray.toCollection(userArray, Muser.class);

或者

String response = "[{name:'hello',age:'12'},{name:'hello',age:'12'}]";

JSONArray datas = JSONArray.fromObject(response);
List<MProceedsAccount> lists = JSONArray.toList(datas, MProceedsAccount.class);

posted @ 2016-08-05 10:03  窗外是绿色的  阅读(1547)  评论(0编辑  收藏  举报