无法正确解析JSON数组

Use*_*er3 1 java android json

我收到以下内容作为Stringwebserveice 的回复:

[
    [
        {
            "dgtype": "adhoc",
            "subtypename": "Person",
            "subtypedesc": "null",
            "summary": "Junaid (Self)",
            "subtype": "person",
            "birthdate": "1995-1-23 ",
            "name": "Junaid (Self)"
        },
        {
            "dgtype": "adhoc",
            "subtypename": "Job",
            "subtypedesc": "null",
            "summary": "Exa",
            "subtype": "person",
            "birthdate": "2010-01-30",
            "name": "Junaid (Self)"
        }
    ]
]
Run Code Online (Sandbox Code Playgroud)

在Java中,我尝试执行以下操作:

JSONArray jArray = new JSONArray(result);  

                System.out.println("Response: "+jArray);

                for(int i = 0; i<= jArray.length(); i++){
                    try {
                        JSONObject oneObject = jArray.getJSONObject(i);

                        String dgtype = oneObject.getString("dgtype");
                        String subtypename = oneObject.getString("subtypename");
                        String subtypedesc = oneObject.getString("subtypedesc");
                        String summary = oneObject.getString("summary");
                        String subtype = oneObject.getString("subtype");
                        String birthdate = oneObject.getString("birthdate");
                        String name = oneObject.getString("name");

                        System.out.println(i);
                        System.out.println("dgtype: "+dgtype);
                        System.out.println("subtypename: "+subtypename);
                        System.out.println("subtypedesc: "+subtypedesc);
                        System.out.println("summary: "+summary);
                        System.out.println("subtype: "+subtype);
                        System.out.println("birthdate: "+birthdate);
                        System.out.println("name: "+name);




                    } catch (JSONException e) {
                        System.out.println("JSON Exception: "+e);
                    } 
                }
Run Code Online (Sandbox Code Playgroud)

但是我得到以下异常:

JSON Exception: org.json.JSONException: Value  
[
    {
        "dgtype": "adhoc",
        "subtypename": "Person",
        "subtypedesc": "null",
        "summary": "Junaid (Self)",
        "subtype": "person",
        "birthdate": "1995-1-23 ",
        "name": "Junaid (Self)"
    },
    {
        "dgtype": "adhoc",
        "subtypename": "Job",
        "subtypedesc": "null",
        "summary": "Exa",
        "subtype": "person",
        "birthdate": "2010-01-30",
        "name": "Junaid (Self)"
    }
]
at 0 of type org.json.JSONArray cannot be converted to JSONObject
JSON Exception: org.json.JSONException: Index 1 out of range [0..1)
Run Code Online (Sandbox Code Playgroud)

我正在关注这个例子.我哪里错了?另请注意异常代码段中缺少的长括号.

Igo*_*pov 5

你有两个数组,一个在另一个数组中:

[
   [
    //Your objects
   ]
]
Run Code Online (Sandbox Code Playgroud)

您可以更改数据格式,使其只有一个数组,或修改您的代码:

JSONArray outer = new JSONArray(result);  
JSONArray jArray = outer.getJSONArray(0);
Run Code Online (Sandbox Code Playgroud)