簡體   English   中英

Alamofire responseJSON無法將NSDictionary類型的值強制轉換為自定義對象

[英]Alamofire responseJSON Could not cast value of type NSDictionary to custom object

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)
        }
    }

無法投射錯誤

“無法將類型'__NSDictionaryI'的值強制轉換為'OperatorsList'。”

如何將Alamofire responseJSON類型轉換為自定義對象?

謝謝!

蘋果沒有提供OJM(對象/ Json映射器)數據綁定功能來將PONSO轉換為JSON,反之亦然。 您可以進行手動映射,也可以使用某些第三方的映射。 例如

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM