我有一个标题:@"This is what taxi drivers know that you don't"
'
是撇号的正确UTF8表示吗?如果是这种情况,则JSON解析器正常工作,其UILabel无法正确显示UTF8。
if ([headline containsString:@"taxi"] == YES) {
news.headLine = [parsedNews objectForKey:@"head_line"];
}
在这个断点处,我看到上面给出的标题,如果您认为UTF8表示错误,我可以在之后发布JSON解析器代码。
答案 0 :(得分:0)
NSString
- >解码为UTF8 NSData
- > NSAttributedString
- > NSString
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *string = @"This is what taxi drivers know that you don't";
NSString *parsed = [self urlDecodeString:string usingEncoding:NSUTF8StringEncoding];
NSLog(@"parsed: %@", parsed);
// parsed: This is what taxi drivers know that you don't
}
- (NSString *)urlDecodeString:(NSString *)string usingEncoding:(NSStringEncoding)encoding
{
NSDictionary *options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(encoding)};
NSData *data = [string dataUsingEncoding:encoding];
NSAttributedString *attString = [[NSAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
return [attString string];
}