我需要解析来自此网址(https://fierce-wildwood-95045.herokuapp.com/categoria)的4个不同数组中的数据,其中一个包含名称,一个包含图片网址,另一个包含其描述。
它应该是这样的:
[1, 2, 3]
答案 0 :(得分:1)
你可以像这样得到Alamofire的结果:
Alamofire.request("https://fierce-wildwood-95045.herokuapp.com/categoria", method: .get, parameters: nil, encoding: URLEncoding.default, headers: [:])
.responseJSON { respone in
let response_array = respone.result.value as! NSArray
var id_array : [NSDictionary] = []
var name_array : [String] = []
var description_array : [String] = []
var image_array : [String] = []
for i in 0..<response_array.count
{
id_array.append(((response_array[i] as! NSDictionary).value(forKey: "_id") as! NSDictionary))
name_array.append(((response_array[i] as! NSDictionary).value(forKey: "nome") as! String))
description_array.append(((response_array[i] as! NSDictionary).value(forKey: "descricao") as! String))
image_array.append(((response_array[i] as! NSDictionary).value(forKey: "urlImagem") as! String))
}
print("id = \(id_array)")
print("name = \(name_array)")
print("description = \(description_array)")
print("image = \(image_array)")
}