如何在android中获取如下所示的嵌套json数组响应?

时间:2014-10-30 07:23:57

标签: android json

如何从android中的URL获取此响应?

 1. //main array   
                [
                         //array in main array     
                         [
                            //object in inner array 
                            {
                                //data to be fetched here 
                                "user_id": "8035",
                                "sr_no": "MG2459",
                                "user_type": "2",
                                "name": "Allen"

                            }
                        ],
                        //2nd array in main array 
                        [     
                            {
                                "user_id": "8035",
                                "sr_no": "MG2459",
                                "user_type": "2",
                                "name": "TestName"

                            }
                        ]


                ]

1 个答案:

答案 0 :(得分:0)

尝试以下代码: -

    try {
        JSONArray ja = new JSONArray(ur string);
        for (int i = 0; i < ja.length(); i++) 
        {
            JSONArray ja1 = ja.getJSONArray(i);
            for (int j = 0; j < ja1.length(); j++) {
                JSONObject jo = ja1.getJSONObject(j);
                String user_id = jo.getString("user_id");
                String sr_no = jo.getString("sr_no");
                String user_type = jo.getString("user_type");
                String name = jo.getString("name");
            }
        }
    } catch (Exception e) {
        // TODO: handle exception
    }