android - How to check if json array has any value? -


i using condition -

if (!obj2.getstring("patroncheckoutinfo").equals("null")) { 

but not work case when array got value.

eg: case1- when json got value "patroncheckoutinfo":

{ "errormessage": "" "message": "operation completed successfully" "status": "ok" "results": { "lookuppatroninforesponse": { "patronaddressinfo": null "patroncheckouthistoryinfo": null "patroncheckoutinfo": [6] 0:  { "author": "cobb, kevin." 

case 2 - when no value:

{ "errormessage": "" "message": "operation completed successfully" "status": "ok" "results": { "lookuppatroninforesponse": { "patronaddressinfo": null "patroncheckouthistoryinfo": null "patroncheckoutinfo": null "patroncirculationinfo": null 

tried few tutorials unable figure out. suggestion welcome. in advance.

you can use support function isnull (http://developer.android.com/reference/org/json/jsonobject.html#isnull(java.lang.string))

so, re-write code in case:

if (!obj2.isnull("patroncheckoutinfo")) { //  } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -