Is the content of the JSON file an array or a simple substance? That
That's why I wrote it with a sudden idea like this. If the first character is [, it is judged to be JSONArray for the time being. Whether or not the string passes through the parser.
if(jsonStr.charAt(0) == '[') {
//JSONArray
} else if(jsonStr.charAt(0) == '{') {
//JSONObject
}
When I was looking for a smarter way, I found something like this
Object object = new JSONTokener(data).nextValue();
if (object instanceof JSONArray) {
//JSONArray
} else if (object instanceof JSONObject) {
//JSONObject
}
I think this is better
end
Recommended Posts