问题描述
我正在开发一个使用套接字和JSON与nodejs服务器通信的应用程序,并且由于iOS 5具有它自己的NSJSONSerialization,所以我认为这可能是遵循的方法.以前,我使用了轻量级的yail库.
I'm in the making of an app that talks to a nodejs-server using sockets and JSON, and since iOS 5 has it's own NSJSONSerialization I thought that's may be the road to follow. Before, I used the lightweight yail library.
无论如何,在迁移到NSJSONSerialization后,我开始遇到编码问题,在更改之前,字符Ö
会很好地发送到服务器并返回,仍然是Ö
,但是现在,NSJSONSerialization留下了仍为unicode char即\U00f6
.
Anyway, after the migration to NSJSONSerialization I started to encounter problem with the encoding, before the change, the character Ö
would send nicely to the server and back, still being Ö
, but now, NSJSONSerialization leaves Ö
still in unicode char i.e. \U00f6
.
阅读文档说明,默认情况下JSON对象已转换为UTF8.而且,当我将服务器的响应转换为简单的NSString时,Ö
会按预期显示,但是它当然仍然是JSON.
Reading the documentation says that JSON objects is converted to UTF8 by default. And when I convert the response from the server to a simple NSString, the Ö
shows up just as expected, but it's still in JSON of course.
请帮助我解决您的问题,所以,我应该返回yail还是使用内置的NSJSONSerialization?
Please help me with your thoughts and so, should I return to yail or use the built-in NSJSONSerialization?
谢谢你,西蒙
推荐答案
NSLog对其参数调用描述,该参数恰好会打印Unicode代码而不是字符本身.尝试例如:
NSLog calls description on its arguments, which happen to print the Unicode code instead of the character itself. Try for example:
NSLog(@"%@", [NSDictionary dictionaryWithObject:@"ö" forKey:@"hello"]);
您将看到它打印
{
hello = "\U00f6";
}
因此,很可能您的JSON解码已经完成.
So, chances are, that your JSON decoding has been done fine.
这篇关于NSJSONSerialization和Unicode不能很好地配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!