/*
* 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;
* 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