还剩6页未读,继续阅读
文本内容:
对象封装成为和解析成封装有对象的List JSONList、封装措施类将放入中发给客户端1JSONArray JSONObjectpackage;import java.util.ArrayList;import org.j son.JSONArray;import org.j son.JSONException;import org.j son.JSONObj ect;import com.mlp.usebean.Messages;import com.mlp.usebean.Resources;import com.mlp.usebean.Types;public classListToJSONArray{public staticJSONArray setListToJRArrayListResourceslist{JSONObjectj son=null;JSONArray ja=new JSONArray;forint i=0;ilist.size;i++{j son=new JSONObject;try H Hj son.put id,list.get i.getRes_id;j son.putname,list.get i.getRes_name;j son.putform”,list.get i.getRes_form;json.putupdate,list.get i.getRes_update;j son.put upuser,list.get i.getRes_upuser;j son.putpatch”,list.get i.getRes_patch;j son.put pass”,list.get i.getRes_pass;HHj son.put downsum,list.get i.getRes_downsum;nj son.putreco list.get i.isRes_reco;zj son.putremark list.get i.getRes_remark;rja.put i,j son;}catch JSONExceptione{//TODO Auto-generated catchblocke.printStackTrace;return ja;public staticJSONArray setListToJTArrayListTypes list{JSONObject j son=null;JSONArray ja=new JSONArray;forint i=0;ilist.size;i++{j son=new JSONObject;try j son.put“id”,list.get i.getType_id;H nj son.put name,list.get i.getType name;j son.putnum”,list.get i.getType num;ja.put ijson;re{}catch JSONException//TODO Auto-generated catchblocke.printStackTrace;}}return ja;public staticJSONArray setListToJMArrayListMessages list{JSONObjectj son=null;JSONArray ja=new JSONArray;forint i=0;ilist.size;i++{json=new JSONObject;try json.put“id”,list.get i.getMes_id;n njson.putreuser list.get i.getMes_user;rn njson.put form,list.get i.getMes_form;Hj son.putreto,list.get i.getMes_to;;json.put date,list,g㊀t ijson.put content,list.get i.g㊀tM㊀s_cont㊀nt;ja.put i,json;}catch JSONExceptione{//TODO Auto-generated catchblock・e printStackTrace;return ja;、解析措施类2package com.chase.db;import java.util.ArrayList;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import android.util.Log;import com.chase.model.Messages;import com.chase.model.MyRes;import com.chase.model.Types;public classJSONArrayToLsit{public staticArrayListMyRes setJRToListJSONArrayja{JSONObject json=null;MyRes re=null;ArrayListMyRes list=new ArrayListMyRes;forint i=O;ija.length;i++{tryre=new MyRes;json=ja.getJSONObjecti;H nre.setResJdjson.getlnt id;Hre.setRes_namejson.getString name;H Hre.setRes_formjson.getString form;H Hre.setRes_updatejson.getString update;nre.setRes_upuserjson.getString upuser;Hre.setRes_passjson.getlntpass;Hre.setRes_downsumjson.getlntdownsum;Hre.setRes_remarkjson.getString remark;,Hre.setRes_patchjson.getString patch;n nre.setRes_recojson.getBoolean reco;H HLog.e jiexi,json.toString;}catch JSONExceptione{//TODO Auto-generated catchblock e.printStackTrace;list.addre;n nLog.e jiexi,list.getO.getRes_name;return list;public staticArrayListMessages setJMToListJSONArrayja{JSONObject json=null;Messages me=null;ArrayListMessageslist=new ArrayListMessages;forint i=O;ija.length;i++{me=new Messages;tryjson=ja.getJSONObjecti;H Hme.setMes_idjson.getlnt id;H Hme.setMes_userjson.getString reuser;n nme.setMes_formjson.getString form;me.setMeS-dateOson.getStringCdate;H Hme.setMes_tojson.getString reto;Hme.setMes_contentjson.getStringcontent;}catch JSONExceptione{//TODO Auto-generated catchblock e.printStackTrace;list.addme;return list;public staticArrayListTypes setJTToListJSONArrayja{JSONObject json=null;Types ty=null;ArrayListTypeslist=new ArrayListTypes;forint i=O;ija.length;i++{ty=new Types;tryjson=ja.get JSONObjecti;H Hty.setTypeJdjson.getlnt id;H nty.setType_namejson.getString name;・ty setType_numjson.getlnt”nurrT;}catch JSONExceptione{//TODO Auto-generated catchblock e.printStackTrace;list.addty;return list;。
个人认证
优秀文档
获得点赞 0