我正在尝试使用é之类的字符解析 XML ,ñ我使用 UTF8 作为编码..
我已经尝试将编码更改为NSISOLatin1StringEncoding但它不起作用
代码是:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
// NSLog(theXML);
[theXML release];
if( xmlParser )
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
if (connection) {
[connection release];
}
}
-(void)callWS {
NSString *url = @"theUrlHere";
NSMutableURLRequest *request =[[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"GET"];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
当我收到 xml 响应时...带有特殊字符的结果出现错误...
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(!soapResults)
{
....//the soapResults here appears wrong when It has special chars...
}
示例:Caperuçú出现çú,Indianópolis出现ópolis