在Swift中的可选型是支持链式解包的;
可是下面的代码中如果用链式解包会不成功:
guard let result = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableLeaves) as? [String:Any] else{
self.printError(message: "JSON数据解析错误")
return
}
但是用括号把 try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableLeaves)
括起来就可以解包成功了。