[英]How to fix issue with unrecognized Special Character on Ipad/Iphone?
I am working on an app that gets a bunch of descriptions through xml and then after parsing puts them on the screen. 我正在开发一个通过xml获取大量描述的应用程序,然后在解析后将其显示在屏幕上。 I'm having a problem with some of the descriptions with apostrophes turning into question marks.
我对某些描述有疑问,其中撇号会变成问号。 What I mean is, they start out in the xml, on the output screen and in the database I get them from as an apostrophe, but then it shows up on the app as a Question mark.
我的意思是,它们以xml开头,在输出屏幕和数据库中以撇号形式出现,但后来在应用程序上显示为问号。 This doesn't always happen, but it does with the same descriptions every time.
这并非总是会发生,但每次都使用相同的描述。 Heres an example:
这里是一个例子:
This is what is in the xml/database 这是xml /数据库中的内容
But it won't be easy.
After a tour of the house, you'll be
This is what shows up on the app: 这是显示在应用程序上的内容:
But it won?t be easy.
After a tour of the house, you?ll be
I'm pretty sure that the problem is that the ipad/iphone doesn't recognize the character that it is receiving...but I have no idea how I would go about fixing it. 我很确定问题是ipad / iphone无法识别它正在接收的字符...但是我不知道如何解决它。 Here is a my Parser code: I believe the xml is being sent as UTF - 8 encoding.
这是我的解析器代码:我相信xml以UTF-8编码发送。
[whereToGetXML appendFormat:xmlID];
NSURL *URL=[[NSURL alloc] initWithString:whereToGetXML];
NSData *dataFromServer = [[NSData alloc] initWithContentsOfURL:URL];
NSLog(@"where to get xml is:%@", whereToGetXML);
// Do any additional setup after loading the view from its nib.
NSData *dataWithoutStringTag = [[NSData alloc]init];
NSXMLParser *firstParser = [[NSXMLParser alloc] initWithData: dataFromServer];
[firstParser setDelegate:self];
[firstParser parse];
//Convert the returned parsed string to data using dataUsingEncoding method. HAVE TO HAVE allowLossyConversion:YES or else it will crash on half of the states.
dataWithoutStringTag =[tempParserString dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion:YES];
NSString *htmlCode = [[NSString alloc] initWithData:dataWithoutStringTag encoding:NSASCIIStringEncoding];
NSMutableString *temp = [NSMutableString stringWithString:htmlCode];
NSData *finalData = [temp dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSXMLParser* parser = [[NSXMLParser alloc] initWithData:finalData];
// NSLog(@"Data is: %@", dataWithoutStringTag);
//NSXMLParser* parser = [[NSXMLParser alloc] initWithData: dataFromServer];
[parser setDelegate: self];
//[parser setShouldResolveExternalEntities:YES];
[parser parse];
[parser release];
It's presumably because the string isn't escaped. 大概是因为字符串没有被转义。
Try adding a backslash before each quotation mark. 尝试在每个引号之前添加一个反斜杠。
\'message\'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.