开发者

Need help with json parsing

开发者 https://www.devze.com 2022-12-24 06:44 出处:网络
I\'m getting this json string info from the server : {\"members\":[[\"sd2840d\",\"Johny\"],[\"jkld341\",\"Marry\"]]}

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));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消