JSON的List数据封装解析方案_第1页
JSON的List数据封装解析方案_第2页
JSON的List数据封装解析方案_第3页
JSON的List数据封装解析方案_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论