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
Post a Comment