I have the following code:
Future<List<Negocio>> fetchPost() async {
print("requesting..");
final response =
await http.get('https://vivicarhue.000webhostapp.com/DBRemota/wsJSONConsultarNegocio.php?categoria=panaderia');
//Revisamos si la respuesta es OK
if (response.statusCode == 200) {
//Listado de objetos json
var jsonList = json.decode(response.body) as List;
//hacemos un mapeo, pasamos cada elemento a un objeto negocio
return jsonList.map((i) => new Negocio.fromJson(i)).toList();
} else {
// si se responde con error, lanzamos una excepción
//para que pueda ser detectada por el builder
throw Exception('Failed to load post');
}
}
and the error I get is:
"type _InternalLinkedHasMap is not a subtype of type List in type cast."
What can be?
The error is that the returned JSON is not a
Array
, but aMap
, first you have to obtain the Array of the field you want, in this case it is 'business', you can do it like this: