【发布时间】:2011-04-04 01:19:00
【问题描述】:
我们正在构建一个 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.
【问题讨论】:
-
您能在实际解析 JSON 的位置显示相关的 Objective-C 代码吗?你用的是什么 JSON 框架?
-
这不是将 JSON 字符串转换为 NSDictionary;这样可行。我知道是因为我在这行后面放了一个 NSLog:github.com/acani/acani-chat/blob/master/Lovers2/…,它表明 JSON 字符串的值的字符已被转换为 ASCII 码。
标签: iphone network-programming node.js redis asyncsocket