JSON解析22

  /*
   * JSON解析
   */
public List<YouhuiquanBean> paramJSONS(String arg1) throws JSONException{
Log.e(YouhuiquanBean.class.getName(), "arg1="+arg1);
List<YouhuiquanBean> parentmList = new ArrayList<YouhuiquanBean>();

JSONObject jsonObject=new JSONObject(arg1);
String status=jsonObject.getString("status");
String tip=jsonObject.getString("tip");
String info=jsonObject.getString("info");
System.out.println("tip:"+tip);
JSONObject info_JSON=new JSONObject(info);
String shop_list=info_JSON.getString("shop_list");
JSONArray mArray = new JSONArray(shop_list);
for (int i = 1; i < mArray.length(); i++) {
List<YouhuiquanchildBean> childmList = new ArrayList<YouhuiquanchildBean>();
YouhuiquanBean mParentBean = new YouhuiquanBean();
JSONObject jsonObject2 = mArray.getJSONObject(i);
mParentBean.setShop_id(jsonObject2.isNull("shop_id") ? "shop_id": jsonObject2.getString("shop_id"));
mParentBean.setShop_name(jsonObject2.isNull("shop_name") ? "" :jsonObject2.getString("shop_name"));

JSONArray coupon_list = jsonObject2.getJSONArray("coupon_list");
// JSONArray jsonArray = new JSONArray(coupon_list);
for (int j = 0; j < coupon_list.length(); j++) {
YouhuiquanchildBean mChildServerBean = new YouhuiquanchildBean();
JSONObject jsonObject3 = coupon_list.getJSONObject(j);
if (coupon_list.isNull(j)) {
break;
}
mChildServerBean.setId(jsonObject3.isNull("id") ? "" : jsonObject3.getString("id"));
mChildServerBean.setAdd_time(jsonObject3.isNull("add_time") ? "" : jsonObject3.getString("add_time"));
mChildServerBean.setPub_num(jsonObject3.isNull("pub_num") ? "" : jsonObject3.getString("pub_num"));
mChildServerBean.setMoney(jsonObject3.isNull("money") ? "5" : jsonObject3.getString("money"));
mChildServerBean.setActive_btime(jsonObject3.isNull("active_btime") ? "" : jsonObject3.getString("active_btime"));
mChildServerBean.setActive_etime(jsonObject3.isNull("active_etime") ? "" : jsonObject3.getString("active_etime"));
mChildServerBean.setCount(jsonObject3.isNull("count") ? "" : jsonObject3.getString("count"));
mChildServerBean.setIs_valid(jsonObject3.isNull("is_valid") ? "" : jsonObject3.getString("is_valid"));

childmList.add(mChildServerBean);
}
mParentBean.setShop_list(childmList);
parentmList.add(mParentBean);
}
return parentmList;

}


2.解析的数据

{"status":"T","tip":"请求数据成功","info":{"shop_list":[{},{"shop_id":"1","shop_name":"小飞象","coupon_list":[{"id":"2","add_time":"2015-07-30 09:13:33","pub_num":"K2015072963390317176339130","money":"","active_btime":"2015年08月01日","active_etime":"2015年08月30日","count":"2","is_valid":"y"}]}]}}


解析在碰到[]时时 JSONArray

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值