开发者

XML answer problem

I tried to read the response data from google weather api, but german umlauts aren't shown correctly. Instead of "ö" I get "^".

I think the problem are those two lines of code:

CXMLElement *resultElement = [nodes objectAtIndex:0];
description = [[[[resultElement attributeForName:@"data"]开发者_如何学JAVA stringValue] copy] autorelease];

How can i get data out of resultElement without stringValue?

PS: I use TouchXML to parse xml


You must be using an NSURLConnection to get your data I suppose. When you receive the data you can convert it to an NSString using appropriate encoding. E.g.

- (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];
    }

}

Here xmlResponse is the NSMutableString that you can pass to your parser. I have used NSISOLatin1 encoding. You can check other kinds of encoding and see what gives you the characters correctly (NSUTF8StringEncoding should do it I suppose).You can check the API doc for a list of supported encodings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜