I am getting an exception while working with JSON library to get data on an android application. It says JSONObject cannot be converted to JSONarray -


this android (java) code, trying fetch data using json library (volley).

private void makejsonarrayrequest() {      jsonarrayrequest req = new jsonarrayrequest(urljsonarry,             new response.listener<jsonarray>() {                 @override                 public void onresponse(jsonarray response) {                     log.d(tag, response.tostring());                      try {                         // parsing json array response                         // loop through each json object                         jsonresponse = "";                         (int = 0; < response.length(); i++)                         {                             jsonobject person = (jsonobject) response.get(i);                             string name = person.getstring("id");                             string email = person.getstring("title");                              jsonresponse += "name: " + name + "\n\n";                             jsonresponse += "email: " + email + "\n\n";                         }                         txtresponse.settext(jsonresponse);                      } catch (jsonexception e) {                         e.printstacktrace();                         toast.maketext(getapplicationcontext(),                                 "error: " + e.getmessage(),                                 toast.length_long).show();                     }                     hidepdialog();                 }             }, new response.errorlistener() {         @override         public void onerrorresponse(volleyerror error) {             volleylog.d(tag, "error: " + error.getmessage());             toast.maketext(getapplicationcontext(),                     error.getmessage(), toast.length_short).show();             hidepdialog();             txtresponse.settext(error.getmessage());         }     });      // adding request request queue     appcontroller.getinstance().addtorequestqueue(req); } 

it works 1 json source link, , not other.

working on json source : http://api.androidhive.info/contacts/

not working on json source : http://cambuzz.co.in/public/inside/app_all.php

the json url provided returns json object (which contains json array)... change jsonarrayrequest jsonobjectrequest.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -