【问题标题】:Return Yahoo! weather API data in Celsius, using YQL返回雅虎!摄氏天气 API 数据,使用 YQL
【发布时间】:2014-02-01 06:00:44
【问题描述】:

我正在尝试使用 Yahoo!以摄氏度为单位的天气 API。

我在请求中添加了&u=c,但它仍在以华氏温度返回数据。

这是我使用的网址:

http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location=%22LEXX0003%22&format=json&u=c

然后回应:

{"query":{"count":1,"created":"2014-01-13T13:06:43Z","lang":"en-US","results":{"channel":{"item":{"title":"Conditions for Beirut, LE at 1:59 pm EET","lat":"33.82","long":"35.48","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Beirut__LE/*http://weather.yahoo.com/forecast/LEXX0003_f.html","pubDate":"Mon, 13 Jan 2014 1:59 pm EET","condition":{"code":"30","date":"Mon, 13 Jan 2014 1:59 pm EET","temp":"64","text":"Partly Cloudy"},"description":"\n<img src=\"http://l.yimg.com/a/i/us/we/52/30.gif\"/><br />\n<b>Current Conditions:</b><br />\nPartly Cloudy, 64 F<BR />\n<BR /><b>Forecast:</b><BR />\nMon - Partly Cloudy. High: 64 Low: 55<br />\nTue - Cloudy. High: 66 Low: 56<br />\nWed - Mostly Sunny. High: 68 Low: 58<br />\nThu - Sunny. High: 70 Low: 60<br />\nFri - Scattered Showers. High: 65 Low: 57<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Beirut__LE/*http://weather.yahoo.com/forecast/LEXX0003_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":"13 Jan 2014","day":"Mon","high":"64","low":"55","text":"Partly Cloudy"},{"code":"26","date":"14 Jan 2014","day":"Tue","high":"66","low":"56","text":"Cloudy"},{"code":"34","date":"15 Jan 2014","day":"Wed","high":"68","low":"58","text":"Mostly Sunny"},{"code":"32","date":"16 Jan 2014","day":"Thu","high":"70","low":"60","text":"Sunny"},{"code":"39","date":"17 Jan 2014","day":"Fri","high":"65","low":"57","text":"Scattered Showers"}],"guid":{"isPermaLink":"false","content":"LEXX0003_2014_01_17_7_00_EET"}}}}}}`

有什么想法吗?

【问题讨论】:

  • 你解决过这个问题吗?

标签: json yahoo yql


【解决方案1】:

迟到总比没有好...

var locationQuery = escape("select item from weather.forecast where woeid in (select woeid from geo.places where text='GB-LND') and u='c'"),
    locationUrl = "http://query.yahooapis.com/v1/public/yql?q=" + locationQuery + "&format=json&callback=?";

如果你把它分开,它会更容易阅读。你我们非常接近,只需要 u=c 作为查询的一部分,而不是在 url 的末尾。

【讨论】:

  • u='c' 不适合我...它钢给我的结果是 F
  • 对我来说是 u="c" 醒来,而不是 u='c'
【解决方案2】:

我用的是yql

select item from weather.forecast where woeid=22724447 and u='c'

它在摄氏度的结果中运行良好。我为该区域的真实 WOEID 更改了“LEXX0003”,它似乎有效。

【讨论】:

    【解决方案3】:

    每当我必须以摄氏度调用我想要的温度时,我只使用一个简单的转换函数:

    function FtoC(temp) {return Math.round((temp - 32) / (9 / 5));}
    

    然后,我想在华氏温度和摄氏温度之间切换。如果您只想使用摄氏温度,那么从 Yahoo 调用摄氏 JSON 元素可能会更好。

    【讨论】:

      【解决方案4】:

      你可以试试这个:

      YQL 查询:

      select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="jiangmen,cn") and u="c"
      

      端点:

      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%22jiangmen%2Ccn%22)%20and%20u%3D%22c%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
      

      我刚刚尝试时的这项工作

      【讨论】:

        【解决方案5】:

        只要这样做,确保它会起作用

        在 YQL 查询末尾添加 -->{ and u="c" }

        例如:

        YQL 查询

        select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="greenland") and u="c"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-02-15
          • 1970-01-01
          • 2012-08-16
          • 1970-01-01
          • 2013-07-06
          • 2016-10-22
          • 1970-01-01
          • 2011-11-15
          相关资源
          最近更新 更多