下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、对象封装成为List和JSON解析成封装有对象的List1、 封装方法类(将JSONArray放入JSONObject中发给客户端)package com.mlp.tools;import java.util.ArrayList;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import com.mlp.usebean.Messages;import com.mlp.usebean.Resources;import com.mlp.usebean.Types;public c
2、lass ListToJSONArray public static JSONArray setListToJR(ArrayList list)JSONObject json=null;JSONArray ja=new JSONArray();for(int i=0;ilist.size();i+)json=new JSONObject();try json.put(id, list.get(i).getRes_id();json.put(name, list.get(i).getRes_name();json.put(form, list.get(i).getRes_form();json.
3、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).getRes_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()
4、;ja.put(i, json); catch (JSONException e) / TODO Auto-generated catch blocke.printStackTrace();return ja;public static JSONArray setListToJT(ArrayList list)JSONObject json=null;JSONArray ja=new JSONArray();for(int i=0;ilist.size();i+)json=new JSONObject();try json.put(id, list.get(i).getType_id();js
5、on.put(name, list.get(i).getType_name();json.put(num, list.get(i).getType_num();ja.put(i, json); catch (JSONException e) / TODO Auto-generated catch blocke.printStackTrace();return ja;public static JSONArray setListToJM(ArrayList list)JSONObject json=null;JSONArray ja=new JSONArray();for(int i=0;ili
6、st.size();i+)json=new JSONObject();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(content, list.get(i).getMes_content();ja.put(i, jso
7、n); catch (JSONException e) / TODO Auto-generated catch blocke.printStackTrace();return ja;2、解析方法类package 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.chas
8、e.model.MyRes;import com.chase.model.Types;public class JSONArrayToLsit public static ArrayList setJRToList(JSONArray ja)JSONObject json=null;MyRes re=null;ArrayList list=new ArrayList();for(int i=0;ija.length();i+)try re=new MyRes();json=ja.getJSONObject(i);re.setRes_id(json.getInt(id);re.setRes_na
9、me(json.getString(name);re.setRes_form(json.getString(form);re.setRes_update(json.getString(update);re.setRes_upuser(json.getString(upuser);re.setRes_pass(json.getInt(pass);re.setRes_downsum(json.getInt(downsum);re.setRes_remark(json.getString(remark);re.setRes_patch(json.getString(patch);re.setRes_
10、reco(json.getBoolean(reco);Log.e(jiexi, json.toString(); catch (JSONException e) / TODO Auto-generated catch blocke.printStackTrace();list.add(re);Log.e(jiexi, list.get(0).getRes_name();return list;public static ArrayList setJMToList(JSONArray ja)JSONObject json=null;Messages me=null;ArrayList list=
11、new ArrayList();for(int i=0;ija.length();i+)me=new Messages();try json=ja.getJSONObject(i);me.setMes_id(json.getInt(id);me.setMes_user(json.getString(reuser);me.setMes_form(json.getString(form);me.setMes_date(json.getString(date);me.setMes_to(json.getString(reto);me.setMes_content(json.getString(con
12、tent); catch (JSONException e) / TODO Auto-generated catch blocke.printStackTrace();list.add(me);return list;public static ArrayList setJTToList(JSONArray ja)JSONObject json=null;Types ty=null;ArrayList list=new ArrayList();for(int i=0;ija.length();i+)ty=new Types();try json=ja.getJSONObject(i);ty.setType_id
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 易涝点排水调蓄方案
- 钨废料分级堆存方案
- 2026江西萍乡安源富民村镇银行客户经理常态化招聘备考题库及答案详解(有一套)
- 2026年第四方物流行业分析报告及未来发展趋势报告
- 2026年发热盘行业分析报告及未来发展趋势报告
- 2026年台州市路桥区教育局公开招聘公办幼儿园劳动合同制教师10人备考题库含答案详解(预热题)
- 温室大棚水肥一体化方案
- 2026福建莆田市卫生健康委员会招聘25人备考题库附答案详解(巩固)
- 2026福建莆田市卫生健康委员会招聘25人备考题库及1套完整答案详解
- 2026云南省文化和旅游厅直属事业单位招聘演员和演奏员7人备考题库及一套答案详解
- 心理健康接纳自己课件
- 癫痫共患偏头痛诊断治疗
- 江西省农发种业有限公司招聘考试真题2024
- 储备土地巡查管理办法
- JJG 688-2025汽车排放气体测试仪检定规程
- 【15万吨日供水量水厂设计中反应沉淀池设计计算过程案例2300字】
- 《铁路线路养护与维修》课件 2.1.5垫板修正作业
- T/CNCA 014-2022改性镁渣基胶凝材料
- 2025年安徽铜陵港航投资建设有限责任公司招聘笔试参考题库附带答案详解
- 1完整版本.5kw机器人专用谐波减速器设计
- CYC指标(指南针成本均线)使用详解
评论
0/150
提交评论