在 Android 中解析 JSONArray
当遇到以 JSONArray 开头的 JSON 数据时,了解解析过程至关重要。以下是如何处理提供的 JSON 来提取“名称”值:
您已正确地将 JSONArray 标识为“abridged_cast”。但是,您的代码当前正在尝试检索“字符”数据。
要获取名称,我们需要迭代 JSONArray 并从每个 JSON 对象中提取“名称”字段。下面是固定的代码片段:
try { //JSON is the JSON code provided in the question JSONObject jsonResponse = new JSONObject(JSON); JSONArray cast = jsonResponse.getJSONArray("abridged_cast"); List<string> allNames = new ArrayList(); for (int i = 0; i <p>代码迭代“abridged_cast”JSONArray,检索每个 JSON 对象,并提取“name”字符串。这些名称存储在 allNames 列表中,生成字符串值:“Jeff Bridges,Charles Grodin,Jessica Lange,John Randolph,Rene Auberjonois。”</p></string>
以上是如何在 Android JSON 解析中从 JSONArray 中提取名称?的详细内容。更多信息请关注PHP中文网其他相关文章!