1 回答

TA貢獻(xiàn)1827條經(jīng)驗 獲得超9個贊
您需要遍歷您的JSONArray,將每個元素轉(zhuǎn)換為 aJSONObject并從每個元素中提取entry和count值,然后從中創(chuàng)建一個字符串并添加到您的列表中:
if (arrOne != null) {
JSONObject entryCountJson;
String entry, count;
for (Object o : arrOne) {
entryCountJson = (JSONObject) o;
entry = String.valueOf(entryCountJson.get("entry"));
count = String.valueOf(entryCountJson.get("count"));
listOne.add("(" + entry + "," + count + ")");
}
}
System.out.println("arrOne: "+arrOne);
System.out.println("listOne: "+listOne);
這輸出:
arrOne: [{"entry":"1","count":1},{"entry":"2","count":1},{"entry":"3","count":1}]
listOne: [(1,1), (2,1), (3,1)]
添加回答
舉報