汉字编码问题ios [英] Chinese Character Encoding Issue ios

查看:109
本文介绍了汉字编码问题ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,因为我支持四种语言.那时,当我使用中文用户名登录时,它向我显示了这样的响应..

I have one app in that I have support four Languages. In that When I am login with Chinese User name at that time it shows me Response like this ..

[{"0":"41","intid":"41","1":"\ u8a00 \ u3046","varfirstname":"\ u8a00 \ u3046" , "2":"\ u8a00 \ u3046","varlastname":"\ u8a00 \ u3046","3":"\ u5730","varusername":"\ u5730","4":"abc@gmail.com ," varemailid:" abc@gmail.com," 5:" qwert," varpassword:" qwert," 6:" 12345," varmobileno:" 12345," 7: "Enable","mobileMessage":"Enable","8":","varphoneno":","9":"Enable","enumstatus":"Enable","10":"2013-01 -30," date_insert:" 2013-01-30," 11:" 2013-01-30," date_edit:" 2013-01-30," 12:" 1.38.28.36, "varipaddress":"1.38.28.36"}]

[{"0":"41","intid":"41","1":"\u8a00\u3046","varfirstname":"\u8a00\u3046","2":"\u8a00\u3046","varlastname":"\u8a00\u3046","3":"\u5730","varusername":"\u5730","4":"abc@gmail.com","varemailid":"abc@gmail.com","5":"qwert","varpassword":"qwert","6":"12345","varmobileno":"12345","7":"Enable","mobileMessage":"Enable","8":"","varphoneno":"","9":"Enable","enumstatus":"Enable","10":"2013-01-30","date_insert":"2013-01-30","11":"2013-01-30","date_edit":"2013-01-30","12":"1.38.28.36","varipaddress":"1.38.28.36"}]

我想向UITextfield Text显示"varfirstname" .但是,当我在NSLog中打印文本时,没有得到任何文本.

I want to Show "varfirstname" to UITextfield Text . But I am not getting any Text when I print it in NSLog .

NSLog(@"Text is === %@",textfname,text);

如何解码此文本?并将其显示在UITextfield或UILabel上.

How can I decode this Text? And show it on UITextfield or UILabel.

推荐答案

我刚刚搜索了它,并从

I just searched it and found one of the useful Answer from here.

中文和日文字符与ASCII字符串编码不兼容是很自然的.如果您尝试通过Apple的方法对字符串进行转义(绝对应该避免代码重复),则将结果存储为Unicode字符串.使用以下编码之一:

It's natural that Chinese and Japanese characters don't work with ASCII string encoding. If you try to escape the string by Apple's methods, which you definitely should to avoid code duplication, store the result as a Unicode string. Use one of the following encodings:

NSUTF8StringEncoding
NSUTF16StringEncoding
NSShiftJISStringEncoding (not Unicode, Japanese-specific)

更新

例如,您可以编码解码中文字符串,如下所示:

For Example you can encode Decode your chinese String like below:

NSString * test = @"汉字马拉松是";
NSString* encodedString =[test stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSLog(@"====%@",encodedString);

输出为:

%E6%B1%89%E5%AD%97%E9%A9%AC%E6%8B%89%E6%9D%BE%E6%98%AF

%E6%B1%89%E5%AD%97%E9%A9%AC%E6%8B%89%E6%9D%BE%E6%98%AF

然后将其解码为:

NSString* originalString =[encodedString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"====%@",originalString);

输出为:

汉字马拉松是

汉字马拉松是

这篇关于汉字编码问题ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆