来自服务器的已知 UTF-8 字符串解码不正确
在我的应用程序中,我从服务器获取一些字符串值,但最终没有得到正确的字符串。
巴塞з
这是来自服务器端的字符串,但我得到的是ءسÙØ·
我尝试在在线解码器中测试响应字符串:
http://www.cafewebmaster.com/online_tools/utf8_encode
它是UTF-8编码的,但我无法在iPhone端解码该字符串。
我查看了这些 Stack Overflow 链接作为参考
将转义的 UTF8 字符转换回其原始形式
objective-c 中的 unicode 转义
utf8_decode for Objective-c
但它们都没有帮助。
In my application, I am getting some string values from a server, but I'm not ending up with the right string.
بسيط
this is the string from server side, but what I am getting is بسÙØ·
I tried to test the response string in an online decoder:
http://www.cafewebmaster.com/online_tools/utf8_encode
It is UTF-8 encoded, but I couldn't decode the string on the iPhone side.
I took a look at these Stack Overflow links as reference
Converting escaped UTF8 characters back to their original form
unicode escapes in objective-c
utf8_decode for objective-c
but none of them helped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我从你的问题中不明白以下几点:
对于第一个问题,我假设服务器被编程为以 UTF-8 编码向您发送文本。
现在,在 iPhone 上,如果您使用套接字发送到服务器,请使用以下命令:
其中函数
writeToServer
是将数据发送到服务器的函数。如果您愿意将数据放入 SQLite3 数据库中,请使用:
如果您从服务器接收数据(再次使用套接字),请执行以下操作:
我希望这涵盖了您需要的所有情况。
I don't understand from your question the following points:
For the first question I will assume that the server is programmed to send you text in UTF-8 encoding.
Now on the iPhone if you are sending to the server using sockets use the following:
Where the function
writeToServer
is your function that will send the data to the server.If you are willing to put the data in a SQLite3 database use:
If you are receiving the data from the server (again using sockets) do the following:
I hope this covers all the cases you need.
没有任何来源,很难说任何结论性的东西,但在某些时候,您将
UTF-8
编码的字符串解释为ISO-8859-1
,并(错误地)转换将其转换为UTF-8
:字符串 '巴沙尼亚' 的分析:
0xD8 0xA8 0xD8 0xB3 0xD9 0x8A 0xD8 0xB7
0xC3 0x98 0xC2 0xA8 0xC3 0x98 0xC2 0xB3 0xC3 0x99 0xC2 0x8A 0xC3 0x98 0xC2 0xB7
因此,在某些时候,您可能应该在代码中找到一些对
ISO-8859-1
的引用。找到它并将其删除。Without any source it is hard to say anything conclusive, but at some point you are interpreting a
UTF-8
encoded string asISO-8859-1
, and (wrongfully) converting it toUTF-8
:Analysis for string 'بسيط':
0xD8 0xA8 0xD8 0xB3 0xD9 0x8A 0xD8 0xB7
0xC3 0x98 0xC2 0xA8 0xC3 0x98 0xC2 0xB3 0xC3 0x99 0xC2 0x8A 0xC3 0x98 0xC2 0xB7
So at some point you should probably find some reference to
ISO-8859-1
in your code. Find it and remove it.已解决此链接的问题
不同类型的UTF8解码在 NSString
NSString *string = @"ءسÙØ·";
我尝试了
这个方法
谢谢。
SOLVED the issue from this link
Different kind of UTF8 decoding in NSString
NSString *string = @"بسÙØ·";
I tried
this method
Thank You.