Skip to content

Instantly share code, notes, and snippets.

@mako34
Created September 27, 2013 04:40
Show Gist options
  • Save mako34/6724220 to your computer and use it in GitHub Desktop.
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
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