seg*_*ggy 6 arrays json ios alamofire swift3
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)
}
Run Code Online (Sandbox Code Playgroud)
结果:
{
"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;
}
Run Code Online (Sandbox Code Playgroud)
我想转换为NSDictionary并获得不同的数组像task_id(数组)但我收到此错误:
"无法将类型'__NSArrayI'的值转换为NSDictionary"
请帮我
先感谢您
Nir*_*v D 14
您的回答是Array的Dictionary没有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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18572 次 |
| 最近记录: |