firemail
标题:
android java 解析复杂json串
[打印本页]
作者:
java
时间:
2017-4-5 18:27
标题:
android java 解析复杂json串
{"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":[]}]}
复制代码
import org.json.JSONArray;
import org.json.JSONObject;
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\":[]}]}";
//String classAllJson = "{\"timeStamp\":1490856881059}";
try {
JSONObject jsonObject = new JSONObject(classAllJson);
long timeStamp = jsonObject.getLong("timeStamp");
JSONArray classDetailArray = jsonObject.getJSONArray("emailClassificationDetailResultList");
for (int i = 0; i < classDetailArray.length(); i++){
JSONObject classInfo = (JSONObject) classDetailArray.get(i);
JSONObject classBaseInfo = classInfo.getJSONObject("emailClassificationBvo");
long id = classBaseInfo.getLong("id");
String name = classBaseInfo.getString("name");
JSONArray classKeysArray = classInfo.getJSONArray("emailClassificationKeysBvoList");
for (int j = 0; j < classKeysArray.length(); j++) {
JSONObject keyInfo = (JSONObject) classKeysArray.get(i);
long idKey = keyInfo.getLong("id");
String nameKey = keyInfo.getString("name");
Integer weight = keyInfo.getInt("weight");
System.out.println(weight);
}
}
} catch (Exception e) {
System.out.println("parseObject Exception " + e);
}
复制代码
欢迎光临 firemail (http://firemail.wang:8088/)
Powered by Discuz! X3