Need help with json parsing

I get this json string information from the server:

{"members":[["sd2840d","Johny"],["jkld341","Marry"]]}

So, I store in a variable:

js = "{\"members\":[[\"sd2840d\",\"Johny\"],[\"jkld341\",\"Marry\"]]}";

and create json object

json = new JSONObject(js);

Naturally, I have many member entries, each member has something like an identifier sd2840dand name Johnyboth lines, how can I create a loop or foreach loop that will be printed .. this is an identifier sd2840dand this is a name Johny, so for Marry, etc. . tnx

+3
source share
1 answer
JSONObject json = new JSONObject(
    "{\"members\":[[\"sd2840d\",\"Johny\"],[\"jkld341\",\"Marry\"]]}");

JSONArray array = json.getJSONArray("members");

for (int idx = 0; idx != array.length(); idx++) {
  JSONArray array2 = array.getJSONArray(idx);
  System.out.println(array2.getString(0));
  System.out.println(array2.getString(1));
}
+1
source

Source: https://habr.com/ru/post/1738961/


All Articles