判断字符串解析是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
//...
}
时刻怀有一颗虔诚之心,乐于分享。知识才更有意义。

浙公网安备 33010602011771号