How to get particular value from JSON response in Android? -


i want value of "result" below json response , store locally.here's code:

private class getcontacts extends asynctask<void, void, void> {          @override         protected void doinbackground(void... arg0) {             // creating service handler class instance             servicehandler sh = new servicehandler();              // making request url , getting response             string jsonstr = sh.makeservicecall(url, servicehandler.get);              if (jsonstr != null) {                     try {                         jsonobject jsonobj = new jsonobject(jsonstr);                          //jsonarray contacts;                         contacts = jsonobj.getjsonarray("response");                         log.d("response: ", "> " + contacts);                      } catch (jsonexception e) {                         e.printstacktrace();                     }                 } else {                     log.e("servicehandler", "couldn't data url");                 }                 return null;         }     } 

my response :

{"response":          [{             "name":"ajay",             "class":"7",         },          {             "rank":1         }],           "date":          {             "startdate":2/12/2012,         },             "result":"pass"         } 

you need create json object json string, , retrieve data:

jsonobject json= new jsonobject(responsestring);  //your response try {     string result = json.getstring("result");    //result key need retrieve data     } catch (jsonexception e) {         // todo auto-generated catch block         e.printstacktrace();     } 

hope helps.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -