本文介绍了unicode在Objective-C中转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串Artîsté".我在PHP上使用了json_encode,并得到了"Art \ u00eest \ u00e9".
I have a string "Artîsté". I use json_encode from PHP on it and I get "Art\u00eest\u00e9".
如何将其转换为NSString?我已经尝试了很多东西,但都无济于事,我总是最后得到Artîsté
How do I convert that to an NSString? I have tried many things and none of them work I always end up getting Artîsté
For Example:
NSString stringWithUTF8String:"Art\u00c3\u00aest\u00c3\u00a9"];//Artîsté
@"Art\u00c3\u00aest\u00c3\u00a9"; //Artîsté
推荐答案
您可以使用CFStringCreateFromExternalRepresentation
和kCFStringEncodingNonLossyASCII
编码来解析\uXXXX
转义序列.在这里查看我的答案:
You can use CFStringCreateFromExternalRepresentation
with the kCFStringEncodingNonLossyASCII
encoding to parse the \uXXXX
escape sequences. Check out my answer here:
这篇关于unicode在Objective-C中转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!