I try to call the POST Api with Alamofire but it's showing me an error of incorrect format.
This is my JSON response:
[ { "_source": { "nome": "LOTERIAS BELEM", "endereco": "R DO COMERCIO, 279", "uf": "AL", "cidade": "BELEM", "bairro": "CENTRO" }, "_id": "010177175" }, { "_source": { "nome": "Bel Loterias" }, "_id": "80224903" }, { "_source": { "nome": "BELLEZA LOTERIAS", "endereco": "R RIVADAVIA CORREA, 498", "uf": "RS", "cidade": "SANTANA DO LIVRAMENTO", "bairro": "CENTRO" }, "_id": "180124986" } ]
class Album: Codable { var _source : [_source] } class _source: Codable { var nome : String var endereco : String var uf : String var cidade : String var bairro : String } var arrList = [Album]()
And this is how i try to Decoding with Alamofire.
func request() { let urlString = URL(string: "My Url") // Alamofire.request(url!).responseJSON {(response) in Alamofire.request(urlString!, method: .post, parameters: ["name": "belem"],encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in switch (response.result) { case .success: if let data = response.data { do { let response = try JSONDecoder().decode([Album].self, from: data) DispatchQueue.main.async { self.arrList = response } } catch { print(error.localizedDescription) } } case .failure( let error): print(error) } } }