博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Json网络解析
阅读量:4559 次
发布时间:2019-06-08

本文共 3463 字,大约阅读时间需要 11 分钟。

上一篇已经本地解析,

接下来只是添加一个网络的异步下载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

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

转载于:https://www.cnblogs.com/shuyongzai/p/4703726.html

你可能感兴趣的文章
Windows Server 2008 R2 备份与恢复详细实例
查看>>
Ubuntu上kubeadm安装Kubernetes集群
查看>>
关于java学习中的一些易错点(基础篇)
查看>>
MFC的多国语言界面的实现
查看>>
四则运算个人项目 最终版
查看>>
java线程系列---java5中的线程池
查看>>
SQL表连接
查看>>
新秀系列C/C++经典问题(四)
查看>>
memset函数具体说明
查看>>
经常使用的android弹出对话框
查看>>
确保新站自身站点设计的合理性的六大注意点
查看>>
1033. 旧键盘打字(20)
查看>>
The Zen of Python
查看>>
git安装及使用
查看>>
mysql一个非常实用解决sql查询优化的函数explain
查看>>
图文讲解NTFS和FAT32硬盘下 asp.net 生成word 错误: 80070005 和 错误:8000401a 的解决方法...
查看>>
《学习》5连接查询(高级查询)
查看>>
python日常—爬取豆瓣250条电影记录
查看>>
11.3NOIP模拟赛
查看>>
1.SDL介绍
查看>>