Use JSONTokener. JSONTokener.nextValue() will give an object which can then be dynamically cast to the appropriate type. Object json = new JSONTokener(jsonResponse).nextValue(); if(json instanceof JSONObject){ JSONObject jsonObject = (JSONObject)json; //further actions on jsonObjects //... }else if (json instanceof JSONArray){ JSONArray jsonArray = (JSONArray)json; //further actions on jsonArray //... }
Determine whether the string is JSONObject or JSONArray
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326701987&siteId=291194637
Recommended
Ranking