雅虎天气 API 响应为 json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5000926/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:45:05  来源:igfitidea点击:

Yahoo weather-api response as json

jsonyahoo-weather-api

提问by Muhammad Zeeshan

I am using yahoo weather apito get weather information

我正在使用雅虎天气 api来获取天气信息

This is returning an xml output.
I want to get it in JSON format. How can i get this as JSON?

这将返回一个 xml 输出。
我想以 JSON 格式获取它。我怎样才能得到它作为 JSON?

回答by seeingidog

I would suggest using YQL and requesting JSON output. The link you referenced is Yahoo's weather RSS feed.

我建议使用 YQL 并请求 JSON 输出。您引用的链接是雅虎的天气 RSS 提要。

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

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

回答by simon04

http://weather.yahooapis.com/forecastjson?w=2502265

http://weather.yahooapis.com/forecastjson?w=2502265

Just replace forecastrssby forecastjsonin the URL. I see one drawback: No weather-codeis returned for the forecast.

只需在 URL 中替换forecastrssforecastjson。我看到一个缺点:没有天气 -code返回预测。

Update 2014-06: This used to work, but seems to be gone since 2012-10 (see also https://developer.yahoo.com/forum/YQL/-/1349591762366-e0f8ad94-f599-49fe-bddb-fe3cd0180dea)

2014-06 更新:这曾经有效,但自 2012-10 年以来似乎消失了(另请参阅https://developer.yahoo.com/forum/YQL/-/1349591762366-e0f8ad94-f599-49fe-bddb-fe3cd0180dea

回答by naveen

As per the documentation at http://weather.yahooapis.com/forecastrss, the rss response is xml.

根据http://weather.yahooapis.com/forecastrss 上的文档,rss 响应是 xml。

The Weather RSS feed is an XML document that conforms to the RSS 2.0 specification. RSS is an XML document containing a single channel element representing the feed, several elements containing metadata about the feed itself, and one or more item elements describing individual items within the feed.

Weather RSS 提要是一个符合 RSS 2.0 规范的 XML 文档。RSS 是一种 XML 文档,其中包含一个表示提要的单个频道元素、几个包含有关提要本身的元数据的元素以及一个或多个描述提要中各个项目的项目元素。

And so, you won't get the response as JSON

所以,你不会得到 JSON 格式的响应

回答by Simone D'Amico

if you are looking for a JSON weather APII have a suggestion for you!
I made a Weather APIavailable on mashape, and they have a ready to use simple PHP SDK. This api is really simple to use because we use the cool standards that are available nowadays, like JSON and REST, while our competitors still use legacy SOAP/XML systems.

如果您正在寻找 JSON天气 API,我有一个建议给您!
我在 mashape 上提供了一个Weather API,他们已经准备好使用简单的 PHP SDK。这个 api 使用起来非常简单,因为我们使用了当今可用的酷标准,如 JSON 和 REST,而我们的竞争对手仍然使用传统的 SOAP/XML 系统。

Speaking about the quality of data Metwit (my "company") born as a crowdsourced platform for gathering real-time weather reports from real people. After more then ten thousand users started to using our apps and send a massive amount of reports, we decided to release those precious reports through our APIs.

谈到数据质量 Metwit(我的“公司”)是一个众包平台,用于从真实的人那里收集实时天气报告。在超过一万用户开始使用我们的应用程序并发送大量报告后,我们决定通过我们的 API 发布这些宝贵的报告。

We also act as single gateway for multiple, hard to parse, sources of forecasts like NOAA, and we're enhancing them with social data like photos, tweets, etc., that we leverage from existing social networks.

我们还充当多个难以解析的预测来源(如 NOAA)的单一网关,并且我们正在利用照片、推文等社交数据增强它们,这些数据来自现有社交网络。

If you like it please give it a try on mashape!

如果您喜欢它,请尝试使用mashape

回答by yubaraj poudel

After a few search i found the yahoo weather api is best for me as what i really needed. To get the weather data from latitude and longitude

经过几次搜索,我发现雅虎天气 api 最适合我,因为我真正需要它。从经纬度获取天气数据

In XML (default)

在 XML 中(默认)

http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="({28.3949},{84.1240})")

In JSON format

JSON 格式

http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="({28.3949},{84.1240})")&format=json

Your ouput will be like belowenter image description here

您的输出将如下所示在此处输入图片说明

Put your own place latitude and longitude to find your location weather, hopefully this will help.

把你自己的地方纬度和经度放在你的位置天气,希望这会有所帮助。