Ios 无法使用JSONJoy从Socket.IO解析JSON数据

Ios 无法使用JSONJoy从Socket.IO解析JSON数据,ios,json,node.js,swift,socket.io,Ios,Json,Node.js,Swift,Socket.io,我正在尝试使用JSONJoy转换从Socket.IO接收的JSON。我有以下JSONJoy协议的结构 struct Order: JSONJoy { let location: String? let username: String? init(_ decoder: JSONDecoder) { location = decoder["location"].string username = decoder["username"].st

我正在尝试使用JSONJoy转换从Socket.IO接收的JSON。我有以下JSONJoy协议的结构

struct Order: JSONJoy {
    let location: String?
    let username: String?

    init(_ decoder: JSONDecoder) {
        location = decoder["location"].string
        username = decoder["username"].string
    }
  }
我已经这样把插座安装好了

socket.on("order") {data, ack in
    let order = Order(JSONDecoder(data))
    print(order)
}
反应总是如此

Order(location: nil, username: nil)
命令是这样发出的

var order = JSON.stringify("{ 'username': 'Test', 'location': 'Start'}");
localSocket.emit('order', order);

我能够确认iOS和服务器端点上的连接

您正在对字符串调用
JSON.stringify
。要么发射字符串,要么将对象字符串化

e、 g


您正在对字符串调用
JSON.stringify
。要么发射字符串,要么将对象字符串化

e、 g

var order = JSON.stringify({username: 'Test', location: 'Start'});