2010-05-27 98 views
0

我試圖從谷歌天氣API讀取響應數據,但德語變音不顯示正確。而不是「ö」我得到「^」。XML答案問題

我認爲這個問題是這些代碼兩行:

CXMLElement *resultElement = [nodes objectAtIndex:0]; 
description = [[[[resultElement attributeForName:@"data"] stringValue] copy] autorelease]; 

我怎樣才能獲得的數據進行resultElement沒有stringValue的?

PS:我用TouchXML解析XML

+0

請發佈您嘗試讀取數據的URL。 – Jim 2010-05-27 10:10:39

+0

#define GOOGLE_WEATHER_SERVICE @「http://www.google.com/ig/api?weather=%@&hl=de」 這就是網址,但我已經測試過該網址。 xml響應與ö正確無誤 – 2010-05-27 10:53:05

回答

2

您必須使用NSURLConnection的,讓您的數據,我想。當您收到數據時,您可以使用適當的編碼將其轉換爲NSString。例如。

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 
    if(xmlResponse == nil){ 
     xmlResponse = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding]; 
    } 
    else{ 
     NSMutableString *temp = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding]; 
     [xmlResponse appendString:temp]; 
     [temp release]; 
    } 

} 

這裏xmlResponse是你可以傳遞給你的解析器的NSMutableString。我使用了NSISOLatin1編碼。您可以檢查其他類型的編碼,並查看正確的字符(NSUTF8StringEncoding應該這樣做)。您可以檢查API文檔以獲取支持的編碼列表。