Created
September 27, 2013 04:40
-
-
Save mako34/6724220 to your computer and use it in GitHub Desktop.
Android / Java check a json to know if is an object or array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSONObject json; | |
Object intervention; | |
JSONArray interventionJsonArray; | |
JSONObject interventionObject; | |
json = RestManager.getJSONfromURL(myuri); // retrieve the entire json stream | |
Object intervention = json.get("intervention"); | |
if (intervention instanceof JSONArray) { | |
// It's an array | |
interventionJsonArray = (JSONArray)intervention; | |
} | |
else if (intervention instanceof JSONObject) { | |
// It's an object | |
interventionObject = (JSONObject)intervention; | |
} | |
else { | |
// It's something else, like a string or number | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment