jam*_*one 6 html unicode objective-c ios
我从一个带有锚标签的API中获取一个字符串,所以我NSAttributedString从中创建了一个字符串,并将其显示在一个UITextView所以我可以支持可点击的链接.
问题是传入的字符串不是有效的HTML,因此它中没有未转义的unicode字符.像:
虽然我可以处理这些特定情况,但我担心任何其他的unicode字符,我目前还不知道.
例:
NSString *fromAPI = @"Reagan \U2014 saying";
NSDictionary *options = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType};
NSData *data = [fromAPI dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
Run Code Online (Sandbox Code Playgroud)
这在UITextView中呈现为: 
如何让它正确渲染em破折号和其他unicode?
找到它,看起来HTML不会渲染unicode,除非你把它添加到 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Run Code Online (Sandbox Code Playgroud)