gpt4 book ai didi

ios - Alamofire responseJSON 无法将 NSDictionary 类型的值转换为自定义对象

转载 作者:行者123 更新时间:2023-11-30 12:48:07 25 4
gpt4 key购买 nike

Alamofire.request(todoEndpoint)
.responseJSON { response in
switch response.result {
case .success(let JSON):
let response: ETOOperatorsList = JSON as! ETOOperatorsList
delegate.requestWithReference(requestReference: "112", model: response as AnyObject)
case .failure(let error):
delegate.requestWithReference(requestReference: "112", error: error)
}
}

无法转换,出现错误

"Could not cast a value of type '__NSDictionaryI' to 'OperatorsList'."

如何将 Alamofire responseJSON 类型转换为自定义对象?

谢谢!

最佳答案

Apple 没有提供用于将 PONSO 转换为 JSON 的 OJM(对象/Json 映射器)数据绑定(bind)功能,反之亦然。您可以进行手动映射,也可以使用第三方的映射。例如

https://github.com/Hearst-DD/ObjectMapper https://github.com/tristanhimmelman/AlamofireObjectMapper

关于ios - Alamofire responseJSON 无法将 NSDictionary 类型的值转换为自定义对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41359554/

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