iphone - 为什么 Objective-C 将 JSON 值转换为 ASCII 字符代码的散列?

标签 iphone network-programming node.js redis asyncsocket

我们正在构建一个 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/

相关文章:

javascript - 在node.js中找不到模块 'connect'

ios - 为什么上下滚动 UITableView 弄乱了我已经更改的 UIButton 标题颜色

iphone - 如何正确保留 NSArray 或基本使用

Java 代理设置

css - 为什么我在使用 create-react-app 的生产构建中丢失了 Bootstrap 样式?

javascript - 为涉及 DataTypes.JSON 的 Sequelize 创建种子文件时出错

iphone - 方向改变时的 UIScrollview 大小

iphone - 来自 App Store 上的应用程序的崩溃报告

c - 从 SSH 服务器发送 channel 请求,使 `ssh_channel_accept_forward()` 在 SSH 客户端上返回?

java - Java中准确检测socket发送失败