【问题标题】:How to get values of nested array of http response by JSON如何通过 JSON 获取 http 响应的嵌套数组的值
【发布时间】:2011-08-10 08:53:54
【问题描述】:

我目前正在 Android 平台上开发 JSON。谁能告诉我如何阅读复杂的 JSON,不胜感激。

我收到以下 JSON 响应

{
    "query": {
        "count":1,
        "created":"2011-08-10T06:09:42Z",
        "lang":"en-US",
        "results": {
            "channel":{
                "item":{
                    "title":"Conditions for Las Vegas, NV at 7:53 pm PDT",
                    "lat":"36.17",
                    "long":"-115.14",
                    "link":"http://us.rd.yahoo.com/dailynews/rss/weather/Las_Vegas__NV/*http://weather.yahoo.com/forecast/USNV0049_f.html",
                    "pubDate":"Tue, 09 Aug 2011 7:53 pm PDT",
                    "condition":{
                        "code":"31",
                        "date":"Tue, 09 Aug 2011 7:53 pm PDT",
                        "temp":"97",
                        "text":"Clear"
                    },
                    "description":"\n<img src=\"http://l.yimg.com/a/i/us/we/52/31.gif\"/><br />\n<b>Current Conditions:</b><br />\nClear, 97 F<BR />\n<BR /><b>Forecast:</b><BR />\nTue - Clear. High: 106 Low: 77<br />\nWed - Sunny. High: 105 Low: 77<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Las_Vegas__NV/*http://weather.yahoo.com/forecast/USNV0049_f.html\">Full Forecast at Yahoo! Weather</a><BR/><BR/>\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)<br/>\n",
                    "forecast":[
                        {
                            "code":"31",
                            "date":"9 Aug 2011",
                            "day":"Tue",
                            "high":"106",
                            "low":"77",
                            "text":"Clear"
                        },{
                            "code":"32",
                            "date":"10 Aug 2011",
                            "day":"Wed",
                            "high":"105",
                            "low":"77",
                            "text":"Sunny"
                        }],
                    "guid":{
                        "isPermaLink":"false",
                        "content":"USNV0049_2011_08_09_19_53_PDT"
                    }
                }
            }
        }
    }
}

告诉我如何获得query.results.chennel.item.titlequery.results.chennel.item,description-element?

【问题讨论】:

  • 问题在哪里?我找不到问题?它在哪里?帮我找问题!请!
  • 首先,您必须添加一些代码并显示真正的问题在哪里,其次:查看 Android 文档中的 JSONObject 和 JSONArray
  • 这里是示例example

标签: android json arrays


【解决方案1】:

JSONObject。你会做类似的事情

String jsonReponse;
// TODO set jsonResponse to {"query": { "count":1,  ...}}
JSONObject response = new JSONObject(jsonReponse);
JSONObject query = response.getJSONObject("query");
JSONObject results = query.getJSONObject("results");
...

【讨论】:

  • 那么请在回答您的问题时打勾。另请注意,您应该检查 null(或添加 Try/catch)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-09
  • 2021-01-31
  • 1970-01-01
  • 1970-01-01
  • 2019-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多