此代码正确显示为Ecole
带有重音E
:
NSString *test = @"\u00c9cole";
cell.detailTextLabel.text = test;
但是当我从服务器获取作为 Json 发送的字符串时,我看到的不是E
重音而是 unicode \u00c9
。
从服务器获取 Json 字符串的代码:
- (void) handleProfileDidDownload: (ASIHTTPRequest*) theRequest
{
NSMutableString *str = [[NSMutableString alloc] init];
[str setString:[theRequest responseString]];
[self preprocess:str]; //NSLog here shows str has the unicode characters \u00c9
}
- (void) preprocess: (NSMutableString*) str
{
[str replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:@"\"" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:@"\\/" withString:@"/" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])];
}
现在,如果我这样做,
cell.detailTextLabel.text = str;
我听不懂 E 而不是 \u00c9
我究竟做错了什么?