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

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

问题描述

我有这样的JSON响应:

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

我要访问项数组对象的值。我试图访问:

  RESPONSE_JSON_OBJECT.getJSONArray(项);

我得到JSON异常。是否有人可以帮助我如何从上面的JSON响应得到JSON阵列?


解决方案

您必须分解完全的对象达到条目阵列。

假设REPONSE_JSON_OBJECT已经是一个被解析的JSONObject。

  REPONSE_JSON_OBJECT.getJSONObject(结果)getJSONObject(图)getJSONArray(进入)。

I have a JSON response like this:

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

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

RESPONSE_JSON_OBJECT.getJSONArray("entry");

I am getting JSON Exception. Can someone please help me on how to get the JSON array from the above JSON response?

解决方案

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

Assuming REPONSE_JSON_OBJECT is already a parsed JSONObject.

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

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

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