utf8_decode用于Objective-C [英] utf8_decode for objective-c
本文介绍了utf8_decode用于Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
objective-c中的Unicode转义
Possible Duplicate:
unicode escapes in objective-c
我有一个LATIN1字符串.
I have a LATIN1 string.
Artîsté
当我对其进行json_encode编码时,它转义了一些字符并将其转换为单字节UTF8.
When I json_encode it, it escapes some chars and converts it to single byte UTF8.
Art\u00eest\u00e9
如果我只是对其进行json_decode解码,我相信它正在使用UTF8进行解码
If I just json_decode it, I believe it is decoding in UTF8
Artîsté
为了找回原始字符串,我必须调用utf8_decode
In order to get my original string back, I have to call utf8_decode
Artîsté
在Objective-C中有没有办法处理这种转换?
Is there a way to handle this conversion in objective-c?
推荐答案
您可能正在寻找:
NSString *string = (some string with non-ASCII characters in it);
char const *string_as_latin1 = [string cStringUsingEncoding:NSISOLatin1StringEncoding];
或者可能是这样:
NSData *data_latin1 = [string dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES];
这篇关于utf8_decode用于Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文