开发者

JSON exception while calling getJSONObject

开发者 https://www.devze.com 2022-12-16 11:34 出处:网络
IN json object if we can found if data exist by jsonobj.has(\"element_name\") by how can we check that data is jsonarray or json object, follow error gives error if only one events element found and t

IN json object if we can found if data exist by jsonobj.has("element_name") by how can we check that data is jsonarray or json object, follow error gives error if only one events element found and throws 开发者_运维百科JSONexception.

JsonObject jObj;
if (json.has("Events")) {
    try {
        JSONArray eventsArray = json.getJSONObject("Events");
    } catch (JSONException e) {
        jObj = json.getJsonObject(""Events"")
    }
}


Is there a reason you're trying to read an array using getJSONObject instead of getJSONArray?

If it's possible that the Events array doesn't always exist, you should be using the optJSONArray method.

If it's a different problem, you'd need to post some example JSON for the success and failure cases to make your question clearer.

0

精彩评论

暂无评论...
验证码 换一张
取 消