0

都市名を取得し、yahoo weather API で天気を表示する簡単なアプリを作成しようとしています。json リクエストを作成して回答を得ることができますが、この json から情報を取得する方法が完全にわかりません。response.query を見ることができますが、 response.query.something を試していると undefined になります。response.query.results.city を取得する方法を誰かに説明してもらえますか?

前もって感謝します!!

https://query.yahooapis.com/v1/public/yql?q=select%20 *%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)% 20where%20text%3D%22greenland%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

{
  "query": {
    "count": 1,
    "created": "2015-11-23T16:18:30Z",
    "lang": "vi",
    "results": {
      "channel": {
        "title": "Yahoo! Weather - Greenland, GL",
        "link": "http://us.rd.yahoo.com/dailynews/rss/weather/Greenland__GL/*http://weather.yahoo.com/forecast/GLXX0012_f.html",
        "description": "Yahoo! Weather for Greenland, GL",
        "language": "en-us",
        "lastBuildDate": "Mon, 23 Nov 2015 12:50 pm CGT",
        "ttl": "60",
        "location": {
          "city": "Greenland",
          "country": "Greenland",
          "region": ""
        },
        "units": {
          "distance": "mi",
          "pressure": "in",
          "speed": "mph",
          "temperature": "F"
        },
        "wind": {
          "chill": "15",
          "direction": "220",
          "speed": "15"
        },
        "atmosphere": {
          "humidity": "63",
          "pressure": "29.8",
          "rising": "0",
          "visibility": "6.21"
        },
        "astronomy": {
          "sunrise": "10:45 am",
          "sunset": "1:33 pm"
        },
        "image": {
          "title": "Yahoo! Weather",
          "width": "142",
          "height": "18",
          "link": "http://weather.yahoo.com",
          "url": "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
        },
        "item": {
          "title": "Conditions for Greenland, GL at 12:50 pm CGT",
          "lat": "71.8",
          "long": "-42.18",
          "link": "http://us.rd.yahoo.com/dailynews/rss/weather/Greenland__GL/*http://weather.yahoo.com/forecast/GLXX0012_f.html",
          "pubDate": "Mon, 23 Nov 2015 12:50 pm CGT",
          "condition": {
            "code": "28",
            "date": "Mon, 23 Nov 2015 12:50 pm CGT",
            "temp": "27",
            "text": "Mostly Cloudy"
          },
          "description": "\n<img src=\"http://l.yimg.com/a/i/us/we/52/28.gif\"/><br />\n<b>Current Conditions:</b><br />\nMostly Cloudy, 27 F<BR />\n<BR /><b>Forecast:</b><BR />\nMon - AM Clouds/PM Sun. High: 29 Low: 17<br />\nTue - Mostly Cloudy. High: 19 Low: 8<br />\nWed - PM Snow Showers. High: 12 Low: 6<br />\nThu - Mostly Cloudy. High: 10 Low: 0<br />\nFri - Mostly Sunny. High: 1 Low: -8<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Greenland__GL/*http://weather.yahoo.com/forecast/GLXX0012_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": "30",
              "date": "23 Nov 2015",
              "day": "Mon",
              "high": "29",
              "low": "17",
              "text": "AM Clouds/PM Sun"
            },
            {
              "code": "28",
              "date": "24 Nov 2015",
              "day": "Tue",
              "high": "19",
              "low": "8",
              "text": "Mostly Cloudy"
            },
            {
              "code": "14",
              "date": "25 Nov 2015",
              "day": "Wed",
              "high": "12",
              "low": "6",
              "text": "PM Snow Showers"
            },
            {
              "code": "28",
              "date": "26 Nov 2015",
              "day": "Thu",
              "high": "10",
              "low": "0",
              "text": "Mostly Cloudy"
            },
            {
              "code": "34",
              "date": "27 Nov 2015",
              "day": "Fri",
              "high": "1",
              "low": "-8",
              "text": "Mostly Sunny"
            }
          ],
          "guid": {
            "isPermaLink": "false",
            "content": "GLXX0012_2015_11_27_7_00_CGT"
          }
        }
      }
    }
  }
}
4

2 に答える 2

0

私がしなければならないことを見つけました(嫌いなjsリスト)。ドット表記を使用して一時を取得しました。記録のためだけに

var response; // here i have the jsonparse thing
//I want to access something I have to do 
response.query.results.channel.wind.speed //and i will get wind's speed

誰かが [] 表記を使用できれば、それは素晴らしいことです。御時間ありがとうございます 。

于 2015-11-23T17:54:03.857 に答える