Android初识-JSON字符串解析详解
来源:互联网 发布:少女前线枪娘数据大全 编辑:程序博客网 时间:2024/06/08 17:51
Json数据结构
{"ResultCode": 1,"Result": {"RecordNum": 4,"ProductNum": 0,"SnNum": 0,"RecordList": [{"Id": "222000002","Name": "沃x金x大酒店","Price": 85.0,"ImageUrl": "http://image.elifemart.com/images/SdImage/Resolution/","ShopCode": "SHOP150500184","ShopName": "沃x金x大酒店中x餐厅","IsStored": "0","MaxPrice": 85.0,"MARKET_PRICE": 100.0,"Shop_address": "xxx","SALEQTY": "124","PDT_INTRODUCTION": "","LATITUDE": "34.572916","LONGITUDE": "113.866047","Distance": 12185.0357,"ISUSE_VIRTUAL": 1.0},{"Id": "222800003","Name": "YHITE3代x金券01","Price": 9.90,"ImageUrl": "xxx","ShopCode": "SHOP150600560","ShopName": "优优KV","IsStored": "0","MaxPrice": 9.90,"MARKET_PRICE": 10.0,"Shop_address": "xxx","SALEQTY": "19","PDT_INTRODUCTION": "YHITE3代金券01","LATITUDE": "34.75661","LONGITUDE": "113.649644","Distance": 12160.8489,"ISUSE_VIRTUAL": 0.0}]}}
解析代码
public static List<ProductItem> parseJsonMulti(String strResult) { List<ProductItem> plist = new ArrayList<ProductItem>(); try { //获取根对象 JSONObject jsonObj = new JSONObject(strResult); //获取根对象下的内容 Integer ResultCode = (Integer) jsonObj.get("ResultCode"); //获取根对象下一级对象 JSONObject jsonResult = jsonObj.getJSONObject("Result"); //获取根对象下一级对象的内容 Integer RecordNum = (Integer) jsonResult.get("RecordNum"); Integer ProductNum = (Integer) jsonResult.get("ProductNum"); Integer SnNum = (Integer) jsonResult.get("SnNum"); //获取根对象下一级对象中的数组对象 JSONArray jsonResults = jsonResult.getJSONArray("RecordList"); //初始化数据到对象中 for(int i = 0; i < jsonResults.length() ; i++){ ProductItem pi = new ProductItem(); JSONObject jsonOne = (JSONObject)jsonResults.get(i); String ProductId = (String) jsonOne.get("Id"); String ProductName = (String) jsonOne.get("Name"); String ProductDes = (String) jsonOne.get("PDT_INTRODUCTION"); Double SalePrice = (Double) jsonOne.get("Price"); Double MarketPrice = (Double) jsonOne.get("MARKET_PRICE"); String SaleQty = (String) jsonOne.get("SALEQTY"); String ImgUrl = (String) jsonOne.get("ImageUrl"); pi.setImgUrl(ImgUrl); pi.setMarketPrice(MarketPrice); pi.setProductDes(ProductDes); pi.setProductId(ProductId); pi.setProductName(ProductName); pi.setSalePrice(SalePrice); pi.setSaleQty(SaleQty); plist.add(pi); } return plist; } catch (JSONException e) { System.out.println("Jsons parse error !"); e.printStackTrace(); } return null; }
0 0
- Android初识-JSON字符串解析详解
- android解析json字符串
- Android解析JSON字符串
- Android Json解析详解
- Android Json解析详解
- JSON解析---初识
- JSON解析 初识
- android的json解析-详解
- 【Android】解析JSON数据详解
- Android Gson解析json详解
- Android Gson解析json详解
- android数据解析之json解析和json字符串创建
- Android解析Json字符串和生成json字符串
- java解析json字符串的两种方法详解(Android通用)
- android json解析详解(json手动解析)
- Android JSON字符串解析和构建
- Android JSON字符串解析和构建 .
- Android JSON字符串解析和构建
- POJ3764 The xor-longest Path(字典树)
- 渣硕的校招求职经历
- MyBatis3和Spring4基于接口编程的例子
- 仿支付宝“数字增长动画”
- Android-->RatingBar自定义大小,自定义样式(图片)
- Android初识-JSON字符串解析详解
- 打造开发神器—Android Studio上的常用5个插件介绍
- OTA打包工具
- mysqlscript文档翻译
- js数组组合
- redis-高级应用
- java实现选择排序算法,sort
- oracle union 和union all 的区别
- GridBagLayout布局管理器学习总结