判断字符串是JSONObject还是JSONArray
使用 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 //... }
相关推荐
somebodyoneday 2020-06-15
83163452 2020-01-28
adonislu 2020-01-10
baijinswpu 2020-01-01
adonislu 2019-12-31
xufankang 2019-12-19
somebodyoneday 2019-12-07
somebodyoneday 2019-10-30
adonislu 2020-06-02
baijinswpu 2020-02-19
adonislu 2020-02-14
baijinswpu 2019-12-28
abcx 2015-05-25
newthon 2019-10-21
iovaaron 2015-04-10
Dolphinsz 2016-04-25
revivre 2017-09-07