[英]Encoding NSString containing 3 byte ASCII characters to a proper NSString
A JSON request returns strings with an HTML encoded Unicode character. JSON请求返回带有HTML编码的Unicode字符的字符串。
It looks like this: valószínű
看起来像这样:
valószínű
which should be decoded to valószínű
应该解码为
valószínű
In other words ű
换句话说
ű
should be ű
. 应该是
ű
。
I found a description about a list of non-standard HTML characters here: http://www.starr.net/is/type/htmlcodes.html 我在这里找到了有关非标准HTML字符列表的描述: http : //www.starr.net/is/type/htmlcodes.html
Is there any easy way to correct this? 有没有简单的方法可以纠正此问题?
It appears that the string is partially escaped. 字符串似乎已部分转义。 If you encode "valószínű" into an NSData object using:
如果使用以下命令将“valószín&#369”编码为NSData对象:
NSData * data = [@"valószínű" dataUsingEncoding:NSUTF8StringEncoding]; NSData *数据= [@“valószín&#369” dataUsingEncoding:NSUTF8StringEncoding];
then created an attributed string using 然后使用创建一个属性字符串
NSAttributedString * attrString = [[NSAttributedString alloc] initWithHTML:data documentAttributes:nil]; NSAttributedString * attrString = [[NSAttributedString alloc] initWithHTML:data documentAttributes:nil];
the "u" will be properly converted, but the preceding marks would be mangled: “ u”将正确转换,但前面的标记将被修饰:
resulting in 导致
valószÃnű 瓦洛斯松
An alternative would be to see the following post: 另一种方法是查看以下帖子:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.