使用 Volley 解析其中包含 JSON 数组的 JSON 对象

Parsing JSON object with JSON array inside it using Volley

我有这样的 Json 回复:

{
    "status" : "CREATED",
    "message" : "user created",
    "results" : [
        {
            "id" : "1243233",
        }
    ]
}

上面的 JSON 响应将通过 POST call.In android 使用 volley 库获得,我做了如下 REST 调用:

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                                url, null,
                                new Response.Listener<JSONObject>() {

                                    @Override
                                    public void onResponse(JSONObject response) {
                                        Log.d("Request", response.toString());
                                        try {
                                            response.getString("status");
                                            JSONArray array = response.getJSONArray("results");

                                                JSONObject id = (JSONObject)array.get(0);




                                            Toast.makeText(getApplicationContext(),response.getString("status"),Toast.LENGTH_LONG).show();
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        pDialog.hide();

                                    }
                                }, new Response.ErrorListener() {

                            @Override
                            public void onErrorResponse(VolleyError error) {
                                VolleyLog.d("Request", "Error: " + error.getMessage());

                                pDialog.hide();
                            }
                        }){
                            @Override
                            public Map<String, String> getHeaders() throws AuthFailureError {
                                HashMap<String, String> headers = new HashMap<String, String>();
                                headers.put("Content-Type", "application/json");
                                return headers;
                            }

                            @Override
                            protected Map<String, String> getParams() throws AuthFailureError {
                                Map<String, String> params = new HashMap<String, String>();
                                params.put("phone", phone);
                                params.put("name", username);
                                params.put("pwd",password);
                                params.put("email", email);
                                return params;
                            }
                        };

                        AppController.getInstance().addToRequestQueue(jsonObjReq);

我遇到错误 org.json.JSONException: Expected literal value at character 102 of

 {
    "status" : "CREATED",
    "message" : "user created",
    "results" : [
        {
            "id" : "1243233",
        }
    ]
}

请帮我解决这个问题。

结果数组的项目中有一个逗号。这意味着应该有另一个元素(字符串、整数等)作为 JSON 对象(结果数组的第一项)的一部分。

因此你得到 JSON 解析错误。

    "results" : [
                   {
                     "id" : "1243233",
                    }
                ]

应该是

   "results" : [
                 {
                      "id" : "1243233"
                 }
               ]

删除逗号