【发布时间】:2020-04-07 18:09:18
【问题描述】:
在我之前使用旧版本的 Alamofire 和 SwiftyJSON 的项目中,使用 JSON(response.result.value) 效果很好。我试图在我的新项目中实现代码,但遇到了一些我以前从未见过的错误。我确实在 SO 上看到了一些关于它的问题,但似乎没有一个解决方案可以解决我的问题(除非我错过了什么)。
AF.request(self.apiEndpoint,
method: .get,
parameters: self.parameters,
headers: self.headers,
interceptor: nil).validate().responseJSON { (response) in
switch response.result {
case .success(let value):
let json = JSON(value)
print(json)
case .failure(_):
print(response)
}
}
这会返回以下错误:
Cannot invoke 'JSON' with an argument list of type '((Any))'
【问题讨论】:
-
responseJSON可以是Anything,您必须将其转换为预期的类型。一个简单的解决方案是将responseJSON替换为responseData -
我遇到了同样的问题:无法使用类型为“((数据))”的参数列表调用“JSON”
-
您可以使用显式初始化程序
JSON(data:,但它也应该按照建议工作。你使用最新版本的 SwiftyJSON 吗? -
是的,我使用的是 cocoapods 可用的最新版本。当我添加标签 JSON(data: value) 时,我得到: Extraneous argument label 'data:' in call
标签: swift alamofire swifty-json