-2

私はiPhoneアプリ開発の初心者です。そして、アプリケーションに Google Weather API を実装しています。チュートリアル コードを使用します。解析には NSXMLParser を使用します。以下のメソッドのチュートリアル コードを削除します。この Google 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

短い XML フラグメントの解析にはRaptureXMLをお勧めします。現在の状態の温度を取得すると、次のようになります (テストされていません)。

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 に答える