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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -