我有这样的json数组:
{"GetReportResult":
[
{"bulan":"4","total":"2448","type":"CHEESE1K","uang":"8847823"},
{"bulan":"4","total":"572476","type":"ESL","uang":"5863408410"},
{"bulan":"4","total":"46008","type":"ESL500ML","uang":"234498301"},
{"bulan":"5","total":"5703","type":"CHEESE1K","uang":"134929306"},
{"bulan":"5","total":"648663","type":"ESL","uang":"6645764498"},
{"bulan":"5","total":"51958","type":"WHP","uang":"631994613"},
{"bulan":"6","total":"6190","type":"CHEESE1K","uang":"104527773"},
{"bulan":"6","total":"443335","type":"ESL","uang":"4540123082"},
{"bulan":"6","total":"30550","type":"ESL500ML","uang":"148302378"},
]
}
这是我想要获取某个对象的代码:
JSONArray weeklyflash = json.getJSONArray("GetReportResult");
JSONObject e = weeklyflash.getJSONObject(i);
String bulan = e.getString("bulan");
if (bulan == 6){
map.put("total1", e.getString("total")); // I want the "total" values are from specified bulan (e.g. bulan == 6)
}
else if (bulan == 5){
map.put("total2", e.getString("total")); // I want the "total" values are from specified bulan (e.g. bulan == 5)
}
else if (bulan == 4){
map.put("total3", e.getString("total")); // I want the "total" values are from specified bulan (e.g. bulan == 4)
}
我得到的是这样的:
total1 | total2 | total3
----------------------------------
2448 | 2448 | 2448
572476 | 572476 | 572476
46008 | 46008 | 46008
我想获取来自指定对象值的值(例如,我想从"total"
where "bulan"
= 5 获取所有值)。怎么做?我想要的是这样的:
total1 | total2 | total3
----------------------------------
6190 | 5703 | 2448
443335 | 648663 | 572476
30550 | 51958 | 46008