无法将“__NSArrayI”(0x10df73c08)types的值转换为“NSDictionary”(0x10df74108)

let url = "http://xyz/index_main.php?c=webservices&a=get&e=007" Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default) .responseJSON { response in print(response) //to get status code if let status = response.response?.statusCode { switch(status){ case 201: print("example success") default: print("error with response status: \(status)") } } //to get JSON return value if let result = response.result.value { let JSON = result as! NSDictionary print(JSON) } 

结果:

  { "create_by" = 007; "create_date" = "2016/06/20"; "due_date" = "2016/06/22"; "estimate_time" = ""; fixer = 007; priority = High; "project_code" = testing; status = "Re-Open"; "task_id" = 228; "task_title" = test; tester = 007; }, { "create_by" = 006; "create_date" = "2016/06/23"; "due_date" = "2016/06/24"; "estimate_time" = ""; fixer = 007; priority = Critical; "project_code" = "tanteida.c"; status = "In Progress"; "task_id" = 234; "task_title" = testing; tester = 006; } 

我想转换为NSDictionary并获得不同的数组像task_id (数组),但我得到这个错误:

“无法将types'__NSArrayI'的值转换为NSDictionary”

请帮帮我

先谢谢你

你的回应是Dictionary Array不是Dictionary ,所以如果你想要所有的字典,你可以使用循环访问它。

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

那是因为你服务以数组的forms返回结果。 你需要做的是将结果投给NSArray。 然后你可以通过索引访问单独的结果:

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