How to check if JSON object is null in Java -


i working on app performs search on server, data transmission based on json, experiencing problems when parsing results, if there no network nullexception when getting information json object, tried checking connection, if connected internet can proceed in situations had internet when requesting data , lost when receiving server nullexception too, thought checking if json object null before tempering it, methods of checking null know have failed, below java code:

 mcommentlist = new arraylist<hashmap<string, string>>();               try {                  // building parameters                 list<namevaluepair> params = new arraylist<namevaluepair>();                 params.add(new basicnamevaluepair("query", searchbox.gettext().tostring()));                   log.d("request!", "starting search");                 // getting product details making http request                 jsonobject json = jsonparser.makehttprequest(search_url, "post",                         params);                  // check log json response                if(json.tostring().isempty())                 {                    log.d("search attempt", json.tostring());                }                 else{                    search = new search();                     search.cancel(true);                    }                  log.d("search attempt", json.tostring()); 

please download necessary junit jar file enable assertion

mcommentlist = new arraylist<hashmap<string, string>>();               try {                  // building parameters                 list<namevaluepair> params = new arraylist<namevaluepair>();                 params.add(new basicnamevaluepair("query", searchbox.gettext().tostring()));                   log.d("request!", "starting search");                 // getting product details making http request                 jsonobject json = jsonparser.makehttprequest(search_url, "post",                         params);                   assertnotnull(json); //for asserting                    // prevent code form breaking                  // check log json response                if(json.tostring().isempty())                 {                    log.d("search attempt", json.tostring());                }                 else{                    search = new search();                     search.cancel(true);                    }                  log.d("search attempt", json.tostring()); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -