私は次のような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