Could not cast value of type '__NSArrayI' (0x10df73c08) to 'NSDictionary' (0x10df74108)

ε祈祈猫儿з 提交于 2019-12-05 06:19:30

Your response is of Array of Dictionary not Dictionary, so if you want all the dictionary you can access it using loop.

if let array = response.result.value as? [[String: Any]] {
    //If you want array of task id you can try like
    let taskArray = array.flatMap { $0["task_id"] as? String }
    print(taskArray)
}

That's because you service returns results in form of an array. What you need to do is to cast result to NSArray. Then you can access separate results by index:

let JSON = result as! NSArray
let firstResult = results[0]

Swift 4.1 +

if let resultArray = jsonResponse.result.value as? [[String: Any]] {
    let taskArray = resultArray.compactMap { $0["task_id"] as? String }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!