iPhone:解析 Google 天气 API 时遇到问题
我正在通过 API 下载 Google 天气。我在解析时遇到问题。
使用 NSXMLParserDelegate,它找到元素“forecast_conditions”,但我似乎无法提取它的内容。解析器似乎认为“高”和“低”等是单独的元素。
这是我尝试解析的一个元素:
<forecast_conditions><day_of_week data="Sun"/><low data="20"/><high data="38"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Clear"/></forecast_conditions>
我很惊讶......
`- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"foundCharacters string: %@",string);
}`
也没有返回任何内容。我认为这解析了元素 Help 的内容
。
I'm downloading Google weather through the API. I'm having trouble parsing.
Using NSXMLParserDelegate, it finds the element "forecast_conditions," but I cannot seem to extract it's content. The parsers seems to think "high" and "low" etc are separate elements.
This is an element I'm try to parse:
<forecast_conditions><day_of_week data="Sun"/><low data="20"/><high data="38"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Clear"/></forecast_conditions>
I'm surprised ...
`- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"foundCharacters string: %@",string);
}`
doesn't return anything either. I thought this parsed the contents of an element
Help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,解析器会自动创建“attributeDict”字典。循环elementNames,只需要调用[attributeDict objectForKey:@"data"]即可。下面的例子。
It turns out the parser creates the "attributeDict" dictionary automatically. Cycling through the elementNames, you only need to call [attributeDict objectForKey:@"data"]. Example below.