android - How to get a more specific result from a JSON object in volley -
this question has answer here:
- sending , parsing json objects [closed] 11 answers
i trying more specific result getting. here code:
// request string response provided url. jsonobjectrequest jsobjrequest = new jsonobjectrequest (request.method.get, url, (string)null, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { try { jsonobject city = response.getjsonobject("city "); mtextview.settext("" + city.tostring()); } catch (jsonexception e) { e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { mtextview.settext("that didn't work!"); } }); mrequestqueue.add(jsobjrequest); }
here screenshot of in return :
more specifically, i'm trying city name when json value returned. how can this?
based on image posted: response.getjsonobject("city").getstring("name");
you have request specific field jsonobject way. city.tostring()
doing supposed do.
@override public void onresponse(jsonobject response) { try { string cityname = response.getjsonobject("city").getstring("name"); mtextview.settext(city); } catch (jsonexception e) { e.printstacktrace(); } }
Comments
Post a Comment