Objective C中的UTF8字符解码 [英] UTF8 character decoding in Objective C

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

问题描述

我正在尝试从我的iPhone上的json webservice解析一个feed但是utf8转换不能正常工作或者我做错了什么
这里是Feed的一部分

est un r\\\Ã \ u00aave en noir

I am trying to parse a feed from a json webservice on my iPhone however the utf8 conversion is not working the way it should or am I doing something wrong Here is apart of the feed
est un r\u00c3\u00aave en noir

这是我写的转换代码以上:

Here is the code I have written to convert the above:

NSString* str1 = @"est un r \u00c3\u00aa ve en noir";

NSString* str = [NSString stringWithUTF8String:[str1 cStringUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"Converted UTF   %@",str);

这是我得到的输出:

转换后的UTF估计值

预期输出应为
转换后的UTF estunrêveennoir

当我检查UTF表并在线使用utf转换器时,使用相同的代码正确获取输出并使用字符串 @est un r\\\êve en noir但我认为UTF16表示如果我没有弄错的话。现在我真正解决了如何解析这个feed。

When I checked the UTF table and used a utf converter online the output is correctly got with the same code and using the string @"est un r\u00EAve en noir" but I think that the UTF16 Representation if I am not mistaken. Now am really in a fix how to parse this feed.

推荐答案

经过多次悲痛之后我才想到这一点。使用它。

After much grief I have figured this out. Use this.

NSString *correctString = [NSString stringWithCString:[utf8String cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];

这篇关于Objective C中的UTF8字符解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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