Parsing JSON Array within JSON Object

后端 未结 5 1643
梦毁少年i
梦毁少年i 2020-11-27 14:45

I have some JSON with the following structure:

{\"source\":[
           {\"name\":\"john\",\"age\":20},
           {\"name\":\"michael\",\"age\":25},
                


        
5条回答
  •  死守一世寂寞
    2020-11-27 15:16

    This could be an answer to your question:

    JSONArray msg1 = (JSONArray) json.get("source");
    for(int i = 0; i < msg1.length(); i++){
      String name = msg1.getString("name");
      int age     = msg1.getInt("age");
    }
    

提交回复
热议问题