我正在使用 Alamofire 作为 HTTP 库,自从更新到 Swift 3 之后,您如何根据下面的示例解析 JSON?
Alamofire.request("https://httpbin.org/get").responseJSON { response in
debugPrint(response)
if let json = response.result.value {
print("JSON: \(json)")
}
}
respone.result.value
是Any对象的,很新很容易混淆。
最佳答案
正如您在 Alamofire tests 中看到的那样你应该将 response.result.value
转换为 [String:Any]
:
if let json = response.result.value as? [String: Any] {
// ...
}
关于ios - 使用新的 Swift 3 和 Alamofire 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39468516/