我们正在构建一个 iPhone 聊天应用程序。
从浏览器向 iPhone 发送 JSON 聊天消息时:
{"content":"Hi"}
iPhone 接收:
{"content":{"0":72,"1":105,"length":2}}
但是,我们打算让它接收完全相同的消息。
要重现此问题,请先安装 node.js 和 redis。然后:
获取代码:
git clone git://github.com/acani/acani.git cd acani git submodule update --init
在默认端口上启动 Redis。
来自 http://github.com/acani/acani-node :
node acani-node-server.js # run node.js chat server # open index.html in a Google Chrome or Firefox and follow instructions.
打开位于 http://github.com/acani/acani-chat/tree/master/Lovers2/ 的 Lovers.xcodeproj ,并更改 LoversAppDelegate.m 以最初加载 ChatViewController 而不是 HomeViewController。
homeViewController = [[HomeViewController alloc] init]; # comment out this line # change the next line to: navigationController = [[UINavigationController alloc] initWithRootViewController:[[ChatViewController alloc] init]]; # Then, build & run.
最佳答案
我们想通了。它根本不是 iPhone 或 Objective-C。转换错误发生在 node.js 服务器上。我们忘记在 JSON 对象的字符串值周围加上引号,所以 JSON.stringify()
JavaScript 函数正在转换字符串,如上所示...除了我们正在做的事情如下:{“内容”:嗨
。当我们将其更改为:{"content":"Hi"}
时,它运行良好。呃……
关于iphone - 为什么 Objective-C 将 JSON 值转换为 ASCII 字符代码的散列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3571673/