java - how do I find out a JSON Object return JSON Array or string in android -
i have json following. how find out json object return json array or string in android.
{ "green_spots": [ ...... ], "yellow_spots": "no yellow spot available", "red_spots": "no red spot available" }
the json objects retrurn array when values present else return string "no green/red/yellow spot available". done following way. there other way do? because alert string changed if not work.
jsonobject obj = new jsonobject(response); string green = obj.getstring("green_spots"); // green spots if ("no green spot available".equalsignorecase(green)) { log.v("search hour", "no green spot available"); } else { jsonarray greenarray = obj.getjsonarray("green_spots"); .... }
object object = jsonobject.get("key"); if (object instanceof jsonobject) { // json object } else if (object instanceof jsonarray) { // json array } else { // string }
Comments
Post a Comment