本文介绍了使用Alamofire序列化JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试序列化JSON响应,但是在 let json = ...行上出现错误。错误是对成员‘jsonObject(with:options :)’的引用不明确。如果有人知道如何解决此问题,我将予以赞赏
Im trying to run to serialize the JSON response, but I am getting an error on the "let json = ..." line. The error is "Ambiguous reference to member 'jsonObject(with:options:)'". If anyone knows how to fix this I will apprechiate it
Alamofire.request("httpbin/get").responseJSON { response in if let JSON = response.result.value { do { let json = try JSONSerialization.jsonObject(with: response.result.value!, options: .allowFragments) } catch { print () } print("JSON: \(JSON)") } }推荐答案
因为 response.result.value 是字典 __ NSDictionaryI 的类型,而不是 jsonObject 。您可以轻松地从 JSON 检索值,而无需转换为json,例如: JSON [ title]
Because response.result.value is type of a dictionary __NSDictionaryI, not a Data as jsonObject expected. You can retrieve value from JSON with ease, no need to convert to json, for example: JSON["title"]
更多推荐
使用Alamofire序列化JSON对象
发布评论