判断json是jsonobject还是jsonarray

如题所述

第1个回答  2017-07-16
区别在于JSONObject是一个{}包裹起来的一个对象(Object),而JSONArray则是[]包裹起来的一个数组(Array),说白点就是一个是数组一个是对象或字符串
第2个回答  2017-07-16
使用 JSONTokener。 JSONTokener.nextValue()会给出一个对象,然后可以动态的转换为适当的类型。 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 //... }
第3个回答  2017-07-16
这个不这样的
相似回答