如何使用 getJSONArray 方法访问 json 对象的嵌套元素 [英] How to access nested elements of json object using getJSONArray method

查看:41
本文介绍了如何使用 getJSONArray 方法访问 json 对象的嵌套元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的 JSON 响应:

I have a JSON response that looks like this:

{
  "result": {
    "map": {
      "entry": [
        {
          "key": { "@xsi.type": "xs:string", "$": "ContentA" },
          "value": "fsdf"
        },
        {
          "key": { "@xsi.type": "xs:string", "$": "ContentB" },
          "value": "dfdf"
        }
      ]
    }
  }
}

我想访问 "entry" 数组对象的值.我正在尝试访问:

I want to access the value of the "entry" array object. I am trying to access:

RESPONSE_JSON_OBJECT.getJSONArray("entry");

我收到 JSONException.有人可以帮我从上面的 JSON 响应中获取 JSON 数组吗?

I am getting JSONException. Can someone please help me get the JSON array from the above JSON response?

推荐答案

您必须分解整个对象才能到达 entry 数组.

You have to decompose the full object to reach the entry array.

假设 REPONSE_JSON_OBJECT 已经是一个解析过的 JSONObject.

Assuming REPONSE_JSON_OBJECT is already a parsed JSONObject.

REPONSE_JSON_OBJECT.getJSONObject("result")
    .getJSONObject("map")
    .getJSONArray("entry");

这篇关于如何使用 getJSONArray 方法访问 json 对象的嵌套元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆