gpt4 book ai didi

ios - 无法将类型 '__NSArrayI' (0x10df73c08) 的值转换为 'NSDictionary' (0x10df74108)

转载 作者:可可西里 更新时间:2023-11-01 03:36:56 25 4
gpt4 key购买 nike

    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(array) 但我收到此错误:

"Could not cast value of type '__NSArrayI' to NSDictionary"

请帮助我

提前致谢

最佳答案

您的响应是 DictionaryArray 而不是 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)
}

关于ios - 无法将类型 '__NSArrayI' (0x10df73c08) 的值转换为 'NSDictionary' (0x10df74108),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40461888/

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