/ / Získajte JSON pole z JSON poľa Java android - java, android, polia, json, arraylist

Získajte pole JSON z poľa JSON Java android - java, android, arrays, json, arraylist

Mám pole JSON a rád by som z neho vybral údaje. Chcel by som získať všetky témy, ale neviem, ako to urobiť.

kód:

JSONObject jsonObject = new JSONObject(thatarray);
JSONArray jsonArray = jsonObject.getJSONArray("response");
int arrSize = jsonArray.length();
List<Integer> sub = new ArrayList<Integer>(arrSize);

for (int i = 0; i < arrSize; ++i) {
jsonObject = jsonArray.getJSONObject(i);
System.out.println("Output: " + jsonObject.toString());
}

odpovede:

1 pre odpoveď č. 1

Vlastne "odpoveď" je jsonObject a "data" je jsonArray .. u môžete rozlišovať medzi jsonArray a jsonObject zobrazením {} a [] ... dúfam, že to pomôže :)

Snažil som sa nižšie kód na vašom JSON a funguje.

 try {
JSONObject jsonObject = new JSONObject(thatarray);
jsonObject = jsonObject.getJSONObject("response");
JSONArray jsonArray = jsonObject.getJSONArray("data");

JSONArray jsonArraysubject;
for (int i = 0; i < jsonArray.length() - 1; i++) {
jsonObject = jsonArray.getJSONObject(i);
jsonArraysubject = jsonObject.getJSONArray("subjects");

Log.d("MyLog", jsonArraysubject + "");
}
} catch (JSONException e) {
e.printStackTrace();
}