-2

我是 Iphone App 开发的新手。我正在我的应用程序中实现 Google Weather API。我使用教程代码,它使用 NSXMLParser 进行解析。我在以下方法中删除了教程代码。我使用这个谷歌 API http://www.google.com/ig/api?weather=nabha

现在我做什么来获得输出。当前温度、高温、低温等

任何提示和解决方案都非常感谢。

谢谢

我的方法是。

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
attributes:(NSDictionary *)attributeDict {


NSLog(@"Processing Element: %@", elementName);


}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 


}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {


}





    2012-07-25 19:20:14.654 XML[4555:f803] Processing Element: xml_api_reply
Current language:  auto; currently objective-c
Processing Element: weather
Processing Element: forecast_information
Processing Element: city
Processing Element: postal_code
Processing Element: latitude_e6
Processing Element: longitude_e6
Processing Element: forecast_date
Processing Element: current_date_time
Processing Element: unit_system
Processing Element: current_conditions
Processing Element: condition
Processing Element: temp_f
Processing Element: temp_c
Processing Element: humidity
Processing Element: icon
Processing Element: wind_condition

   etc......
  2012-07-25 19:20:44.042 XML[4555:f803] No Errors
4

1 回答 1

0

我会推荐RaptureXML来解析短 XML 片段。获取当前条件温度看起来像这样(未经测试):

RXMLElement *root = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://www.google.com/ig/api?weather=nabha"]];

RXMLElement *currentConditions = [root child:@"current_conditions"];
RXMLElement *tempC= [currentConditions child:@"temp_c"];
NSLog(@"temperature (C): %@", [tempC attribute:@"data"]);
于 2012-07-25T14:14:52.973 回答