![](/img/trans.png)
[英]Swift: Could not cast value of type '__NSCFArray' to '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.