I am getting a JSON string back from my server, which can be either a JSONArray
or a JSONObject
, and I do not know beforehand what I'll get (at least not in that part of the code).
Is there a way to handle this? My first guess would be to do something like this:
if (jsonString.startsWith("[")) {
r = new JSONArray(jsonString);
} else {
r = new JSONObject(jsonString);
}
but this feels a little 'hackish'.