android - How to get a more specific result from a JSON object in volley -


this question has answer here:

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 : enter image description here

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

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -