2

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"}]

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);

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vivek2012
  • 772
  • 1
  • 13
  • 25
  • I'm a Chinese developer myself, I think I can help you out with this one, but would you please tell me how do you get this `textfname` from that JSON string? – Zhao Xiang Jan 31 '13 at 06:02
  • I think what you're looking for is http://stackoverflow.com/questions/4404714/converting-strings-containing-u-to-characters-on-ios-iphone – Zhao Xiang Jan 31 '13 at 06:05

2 Answers2

3

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

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)

UPDATE

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

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

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

OUTPUT IS:

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

Then Decode it like:

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

OUTPUT IS:

汉字马拉松是

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • Thaks buddy for Prompt Reply . Can U provide some code on this . i have try all the Encoding things and all . I have shown you my Response and I want to Just show that String on UITextfield .. – Vivek2012 Jan 31 '13 at 05:57
  • check my updated Answer Please and tel me its working or not for you.? – Nitin Gohel Jan 31 '13 at 06:07
  • U save me Bro .. Only this Bug has been left in my app . Working since Last ni8 .. Thanks again Bro .. – Vivek2012 Jan 31 '13 at 06:14
  • @NitinGohel Please check what I am doing wrong and answer my question hear http://stackoverflow.com/questions/43539307/how-to-post-string-with-special-character-and-thai-language-using-xml-parsing-in. – Muju Apr 22 '17 at 08:58
1
NSString *abc = @"\u8a00\u3046";

NSLog(@" %@ " , [NSString stringWithUTF8String:[abc UTF8String]]);

and if you use json :

NSString *html = @"\u8a00\u3046";

NSData *jsonData = [html dataUsingEncoding:NSUTF8StringEncoding];

NSLog(@" %@ " , [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);

they all output "言う" I think it is Japanese

Guo Luchuan
  • 4,729
  • 25
  • 33