作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 JSONJoy 转换从 Socket.IO 接收到的 JSON。我有以下 JSONJoy 协议(protocol)结构
struct Order: JSONJoy {
let location: String?
let username: String?
init(_ decoder: JSONDecoder) {
location = decoder["location"].string
username = decoder["username"].string
}
}
我的Socket是这样设置的
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
。要么只发出字符串,要么将对象字符串化。
例如
var order = JSON.stringify({username: 'Test', location: 'Start'});
关于ios - 无法使用 JSONJoy 解析来自 Socket.IO 的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32899073/
https://github.com/daltoniam/JSONJoy-Swift例如: JSON1 = { "message": "Sorry! Password does not match."
我正在尝试使用 JSONJoy 转换从 Socket.IO 接收到的 JSON。我有以下 JSONJoy 协议(protocol)结构 struct Order: JSONJoy { let
我在为需要由 JSONJoy 协议(protocol)实现的 Swift init 方法获取 Objective-C 选择器时遇到问题。我希望能够获得 init 方法的选择器的原因是,我可以根据类名以
我是一名优秀的程序员,十分优秀!