Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2201|回复: 0
打印 上一主题 下一主题

android java 解析复杂json串

[复制链接]

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
跳转到指定楼层
楼主
发表于 2017-4-5 18:27:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. {"timeStamp":1490856881059,"emailClassificationDetailResultList":[{"emailClassificationBvo":{"id":3,"name":"购物促销"},"emailClassificationKeysBvoList":[{"id":1,"name":"双11","weight":1},{"id":2,"name":"订单","weight":2}]},{"emailClassificationBvo":{"id":4,"name":"银行金融"},"emailClassificationKeysBvoList":[{"id":3,"name":"信用卡","weight":1},{"id":4,"name":"银行","weight":2}]},{"emailClassificationBvo":{"id":5,"name":"其他信息"},"emailClassificationKeysBvoList":[]}]}
复制代码
  1. import org.json.JSONArray;
  2.         import org.json.JSONObject;


  3.         String classAllJson = "{\"timeStamp\":1490856881059,\"emailClassificationDetailResultList\":[{\"emailClassificationBvo\":{\"id\":3,\"name\":\"购物促销\"},\"emailClassificationKeysBvoList\":[{\"id\":1,\"name\":\"双11\",\"weight\":1},{\"id\":2,\"name\":\"订单\",\"weight\":2}]},{\"emailClassificationBvo\":{\"id\":4,\"name\":\"银行金融\"},\"emailClassificationKeysBvoList\":[{\"id\":3,\"name\":\"信用卡\",\"weight\":1},{\"id\":4,\"name\":\"银行\",\"weight\":2}]},{\"emailClassificationBvo\":{\"id\":5,\"name\":\"其他信息\"},\"emailClassificationKeysBvoList\":[]}]}";
  4.         //String classAllJson = "{\"timeStamp\":1490856881059}";
  5.         try {
  6.             JSONObject jsonObject = new JSONObject(classAllJson);
  7.             long timeStamp = jsonObject.getLong("timeStamp");
  8.             JSONArray classDetailArray = jsonObject.getJSONArray("emailClassificationDetailResultList");
  9.             for (int i = 0; i < classDetailArray.length(); i++){
  10.                 JSONObject classInfo = (JSONObject) classDetailArray.get(i);
  11.                 JSONObject classBaseInfo = classInfo.getJSONObject("emailClassificationBvo");
  12.                 long id = classBaseInfo.getLong("id");
  13.                 String name = classBaseInfo.getString("name");
  14.                 JSONArray classKeysArray = classInfo.getJSONArray("emailClassificationKeysBvoList");
  15.                 for (int j = 0; j < classKeysArray.length(); j++) {
  16.                     JSONObject keyInfo = (JSONObject) classKeysArray.get(i);
  17.                     long idKey = keyInfo.getLong("id");
  18.                     String nameKey = keyInfo.getString("name");
  19.                     Integer weight = keyInfo.getInt("weight");
  20.                     System.out.println(weight);
  21.                 }
  22.             }

  23.         } catch (Exception e) {
  24.             System.out.println("parseObject Exception " + e);
  25.         }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-11-26 07:14 , Processed in 0.056075 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表