判断字符串解析是JsonObject或者JsonArray

如下,用 JSONTokener 实现:

Object json = new JSONTokener(stringData).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
    //...
}

  

原文地址:https://www.cnblogs.com/spring87/p/5649500.html