android - Parsing JSON object with JSON array inside it using Volley -


i have json reponse this:

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

the above json response obtained post call.in android using volley library did rest call following:

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

i getting error org.json.jsonexception: expected literal value @ character 102 of

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

please me solve this.

there comma in results array's item. means there should element(string,integer etc) part of jsonobject(first item of results array).

hence json parsing error.

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

should be

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

removing comma


Comments