小编Nee*_*esh的帖子

JSON Java检查元素是JSONArray或JSONObject

如何检查元素是JSONArray还是JSONObject.我写了代码来检查,

if(jsonObject.getJSONObject("Category").getClass().isArray()) {

} else {

}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如果元素'category'是JSONObject,那么它工作正常,但如果它包含一个数组,那么它会抛出异常:JSONArray无法转换为JSONObject.请帮忙.谢谢.

java android json web-services

20
推荐指数
3
解决办法
3万
查看次数

使用Gson读取Json字符串结果错误"不是JSON数组"

在我的项目中,我有一个复杂的json响应.我想通过GSon阅读它.

JSON : {'FoodMenuRS':{'Results':[{'Items':{'Item':[{'@Id':'24'},{'@Id':'24'}]}}, {'Items':{'Item':{'@Id':'24'}}}]}}
Run Code Online (Sandbox Code Playgroud)

它包含一个带有第一个"Item"的JSONArray和带有第二个的JSONObject.因此它的调用导致错误,

failed to deserialize json object {"@Id":"24"} given the type java.util.List<com.servlet.action.ItemInfo>  and  java.lang.IllegalStateException: This is not a JSON Array.
Run Code Online (Sandbox Code Playgroud)

请帮助我应该如何处理这种情况.谢谢.

javascript java android json gson

4
推荐指数
1
解决办法
4932
查看次数

标签 统计

android ×2

java ×2

json ×2

gson ×1

javascript ×1

web-services ×1