json 返回雅虎!摄氏天气 API 数据,使用 YQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21092164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Return Yahoo! weather API data in Celsius, using YQL
提问by Khodour.F
I'm trying to get Yahoo! weather API with temperatures in Celsius.
我正在尝试获取 Yahoo! 温度为摄氏度的天气 API。
I've added &u=cin the request, but it's still returning data in Fahrenheit.
我已经&u=c在请求中添加了,但它仍然以华氏温度返回数据。
This is the URL I'm using:
这是我正在使用的网址:
And the response:
和回应:
{"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"}}}}}}`
Any ideas?
有任何想法吗?
回答by DanV
Better late than never...
迟到总比不到好...
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=?";
It's easier to read if you break it up. You we're pretty close, just needed the u=c as part of the query, not at the end of the url.
如果你把它拆开,阅读起来会更容易。你我们很接近,只需要 u=c 作为查询的一部分,而不是在 url 的末尾。
回答by Aris
I used the yql
我使用了 yql
select item from weather.forecast where woeid=22724447 and u='c'
and it worked fine with the results in Celsius. I changed the "LEXX0003" for the real WOEID of that zone and it seems to have worked.
并且它在摄氏度的结果中运行良好。我为该区域的真实 WOEID 更改了“LEXX0003”,它似乎起作用了。
回答by Zhao Weihao
You can try this:
你可以试试这个:
YQL Query:
YQL 查询:
select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="jiangmen,cn") and u="c"
EndPoint:
终点:
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
This work when I try just now
当我刚刚尝试时这项工作
回答by Michael Howard
Whenever I had to call a temperature that I wanted in Celsius I just used a simple conversion function:
每当我不得不调用我想要的摄氏温度时,我只使用一个简单的转换函数:
function FtoC(temp) {return Math.round((temp - 32) / (9 / 5));}
Then again, I wanted to toggle between Fahrenheit and Celsius. Just calling the Celsius JSON element from Yahoo is probably better if all you want to use is Celsius.
再说一次,我想在华氏度和摄氏度之间切换。如果您只想使用摄氏度,那么从雅虎调用摄氏度 JSON 元素可能会更好。
回答by Helia Fathi
just do this,be sure it will work
只需这样做,确保它会起作用
add this -->{ and u="c"} at the end of the YQL Query
在 YQL 查询的末尾添加这个 -->{和 u="c"}
for example:
例如:
YQL Query
YQL查询
select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="greenland") and u="c"

