gpt4 book ai didi

ios - 使用新的 Swift 3 和 Alamofire 解析 JSON

转载 作者:IT王子 更新时间:2023-10-29 05:29:13 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com