判断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
这个不这样的

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网