简体   繁体   English

解析雅虎天气RSS Feed

[英]Parse Yahoo Weather RSS Feed

I need to parse the Yahoo Weather RSS feed for a place, like http://weather.yahooapis.com/forecastrss?w=44418&u=c for example, to get the high, low, current temperature and the weather image eg. 我需要解析一个地方的Yahoo Weather RSS feed,例如http://weather.yahooapis.com/forecastrss?w=44418&u=c ,以获得高,低,当前温度和天气图像,例如。 sun and clouds image, for the current day. 太阳和云彩图像,为当天。

I'd like to do this in Cocoa (Mac). 我想在Cocoa(Mac)中这样做。

Any help would be appreciated, thanks! 任何帮助将不胜感激,谢谢!

You have two ways, how you could solve this: 你有两种方法,如何解决这个问题:

Use a wrapper 使用包装器

If you wan't to solve the problem the easy way, you could use a soloution someone already programmed for you for example this simple wrapper . 如果您不想以简单的方式解决问题,您可以使用已经为您编程的解决方案,例如这个简单的包装器 The problem is that this wrapper just fetches basic things like temperature etc. If you want more informations you'll have to extend the code, but I think that shouldn't be a big problem. 问题是这个包装器只是提取温度等基本的东西。如果你想要更多的信息,你将不得不扩展代码,但我认为这不应该是一个大问题。

Here is an usage example: 这是一个用法示例:

#import "SCYahooWeatherParser.h"
// ...
SCYahooWeatherParser *parser = [[SCYahooWeatherParser alloc] initWithWOEID:woeid weatherUnit: SCWeatherUnitCelcius];
SCYahooWeather *result = [parser parse];
// now you can handle the parameters of result by yourself.

Use a XML Parser 使用XML Parser

If you wan't you can solve it also the hard, but cleaner way. 如果你不能解决它也是一种艰难但更清洁的方式。 You can Download the XML from their servers and parse it with a XML Parser. 您可以从其服务器下载XML并使用XML Parser进行解析。 For this I recommend you to first read the documentation of the Yahoo weather API . 为此,我建议您先阅读Yahoo weather API文档 Than when you know what you're doing I recommend you to use TouchXML for parsing the XML data, because this is a very good XML Parser, which is also use by a lot of people. 当你知道自己在做什么时,我建议你使用TouchXML来解析XML数据,因为这是一个非常好的XML解析器,很多人也使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM