欢迎来到天天文库
浏览记录
ID:56825803
大小:27.00 KB
页数:4页
时间:2020-07-15
《JSON的List数据封装解析方案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、对象封装成为List和JSON解析成封装有对象的List1、封装方法类(将JSONArray放入JSONObject中发给客户端)packagecom.mlp.tools;importjava.util.ArrayList;importorg.json.JSONArray;importorg.json.JSONException;importorg.json.JSONObject;importcom.mlp.usebean.Messages;importcom.mlp.usebean.Resources;
2、importcom.mlp.usebean.Types;publicclassListToJSONArray{publicstaticJSONArraysetListToJR(ArrayListlist){JSONObjectjson=null;JSONArrayja=newJSONArray();for(inti=0;i3、json.put("name",list.get(i).getRes_name());json.put("form",list.get(i).getRes_form());json.put("update",list.get(i).getRes_update());json.put("upuser",list.get(i).getRes_upuser());json.put("patch",list.get(i).getRes_patch());json.put("pass",list.get(i).ge4、tRes_pass());json.put("downsum",list.get(i).getRes_downsum());json.put("reco",list.get(i).isRes_reco());json.put("remark",list.get(i).getRes_remark());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}publ5、icstaticJSONArraysetListToJT(ArrayListlist){JSONObjectjson=null;JSONArrayja=newJSONArray();for(inti=0;i6、t.get(i).getType_num());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}publicstaticJSONArraysetListToJM(ArrayListlist){JSONObjectjson=null;JSONArrayja=newJSONArray();for(inti=0;i7、++){json=newJSONObject();try{json.put("id",list.get(i).getMes_id());json.put("reuser",list.get(i).getMes_user());json.put("form",list.get(i).getMes_form());json.put("reto",list.get(i).getMes_to());json.put("date",list.get(i).getMes_date());json.put("conte8、nt",list.get(i).getMes_content());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}}2、解析方法类packagecom.chase.db;importjava.util.ArrayList;importorg.json.JSONArray;im
3、json.put("name",list.get(i).getRes_name());json.put("form",list.get(i).getRes_form());json.put("update",list.get(i).getRes_update());json.put("upuser",list.get(i).getRes_upuser());json.put("patch",list.get(i).getRes_patch());json.put("pass",list.get(i).ge
4、tRes_pass());json.put("downsum",list.get(i).getRes_downsum());json.put("reco",list.get(i).isRes_reco());json.put("remark",list.get(i).getRes_remark());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}publ
5、icstaticJSONArraysetListToJT(ArrayListlist){JSONObjectjson=null;JSONArrayja=newJSONArray();for(inti=0;i6、t.get(i).getType_num());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}publicstaticJSONArraysetListToJM(ArrayListlist){JSONObjectjson=null;JSONArrayja=newJSONArray();for(inti=0;i7、++){json=newJSONObject();try{json.put("id",list.get(i).getMes_id());json.put("reuser",list.get(i).getMes_user());json.put("form",list.get(i).getMes_form());json.put("reto",list.get(i).getMes_to());json.put("date",list.get(i).getMes_date());json.put("conte8、nt",list.get(i).getMes_content());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}}2、解析方法类packagecom.chase.db;importjava.util.ArrayList;importorg.json.JSONArray;im
6、t.get(i).getType_num());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}publicstaticJSONArraysetListToJM(ArrayListlist){JSONObjectjson=null;JSONArrayja=newJSONArray();for(inti=0;i7、++){json=newJSONObject();try{json.put("id",list.get(i).getMes_id());json.put("reuser",list.get(i).getMes_user());json.put("form",list.get(i).getMes_form());json.put("reto",list.get(i).getMes_to());json.put("date",list.get(i).getMes_date());json.put("conte8、nt",list.get(i).getMes_content());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}}2、解析方法类packagecom.chase.db;importjava.util.ArrayList;importorg.json.JSONArray;im
7、++){json=newJSONObject();try{json.put("id",list.get(i).getMes_id());json.put("reuser",list.get(i).getMes_user());json.put("form",list.get(i).getMes_form());json.put("reto",list.get(i).getMes_to());json.put("date",list.get(i).getMes_date());json.put("conte
8、nt",list.get(i).getMes_content());ja.put(i,json);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnja;}}2、解析方法类packagecom.chase.db;importjava.util.ArrayList;importorg.json.JSONArray;im
此文档下载收益归作者所有