I'm getting this json string info from the server :
{"members":[["sd2840d","Johny"],["jkld341","Marry"]]}
So I store in in variable :
js = "{\"members\":[[\"sd2840d\",\"Johny\"],[\"jkld341\",\"Marry\"]]}";
and create json object
json = new JSONObject(js);
Naturally I have many occurences of members, each member has something like identifier sd2840d
and name Johny
both strings, how 开发者_StackOverflow社区can I create for loop or foreach loop that will print out .. this is identifier sd2840d
and this is name Johny
, so on for Marry etc. tnx
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));
}
精彩评论