上一篇已经本地解析,
接下来只是添加一个网络的异步下载volley
1、首先导包volley,没找到的这里有一个
http://download.csdn.net/detail/azhansy/8956161
2、在上一篇的基础上添加:
RequestQueue requestQueue = Volley.newRequestQueue(this); //网络链接,记得给INTERNET权限! String JSONDataUrl = "http://sjshop.easyder.com/app/order_index/getCart?buyer_id=511"; JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( Request.Method.GET, JSONDataUrl, null, new Response.Listener() { @Override public void onResponse(JSONObject response) { //把网络返回来的数据JSONObject解析出来 getcartJson(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError arg0) { System.out.println("sorry,Error"); } }); requestQueue.add(jsonObjectRequest);
只要把response接到本地获取的数据JSONObject,然后解析出来,方法为
//getcart的网络解析,参数--》JSONObject public void getcartJson(JSONObject jsonObject) { try { JSONObject objectInfo = jsonObject.getJSONObject("info"); JSONArray arraygroup = objectInfo.getJSONArray("group"); for (int i = 0; i < arraygroup.length(); i++) { ShopBean shopBean = new ShopBean(); JSONObject item = arraygroup.getJSONObject(i); int seller_uid = item.getInt("seller_uid"); String seller_name = item.getString("seller_name"); shopBean.setSeller_uid(seller_uid); shopBean.setSeller_name(seller_name); JSONArray arraygoods = item.getJSONArray("goods"); for (int j = 0; j < arraygoods.length(); j++) { JSONObject jtem = arraygoods.getJSONObject(j); int stock_id = jtem.getInt("stock_id"); String goods_name = jtem.getString("goods_name"); int qty = jtem.getInt("qty"); boolean is_choose = jtem.getBoolean("is_choose"); int price = jtem.getInt("price"); String goods_img = jtem.getString("goods_img"); String extend = jtem.getString("extend"); int stock_num = jtem.getInt("stock_num"); int goodsTotalPrice = jtem.getInt("goodsTotalPrice"); double rate = jtem.getDouble("rate"); //把商品的属性值添加到shop实体类中 shopBean.setStock_id(stock_id); shopBean.setGoods_name(goods_name); shopBean.setQty(qty); shopBean.setIs_choose(is_choose); shopBean.setPrice(price); shopBean.setGoods_img(goods_img); shopBean.setExtend(extend); shopBean.setStock_num(stock_num); shopBean.setGoodsTotalPrice(goodsTotalPrice); shopBean.setRate(rate); shopBeanList.add(shopBean); } textView.append(shopBeanList.get(i).toString()); } } catch (Exception e) { } }发源代码出来,大家学习学习
http://download.csdn.net/detail/azhansy/8956271
版权声明:本文为博主原创文章,未经博主允许不得转载。