当前我正在使用SwiftyJSON
将数据集转换为JSON类型。从'JSON'投射到无关类型'String'始终失败
当我运行这个:print(json)
时,它将在Xcode控制台上打印。
{
"user_id": "123999923821"
}
但是,只要我尝试执行json["user_id"] as? String
,它总是返回nil。
socketManager.socket.on("toAllDrivers") { data, ack in
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "PopViewControllerID") as? PopUpViewController {
let json = JSON(data[0])
print(json)
vc.passenger_id = json["user_id"] as? String // This is the line of code that return a problem.
self.present(vc, animated: true, completion: nil)
}
}
vc.passenger_id
是一个String类型:
var passenger_id: String?
的错误是:从 'JSON'
演员到不相关类型的 '字符串' 总是失败
什么我应该怎样解决这个问题?