Trying to parse json response, works fine with string, int type values. But getting error when having list as values even after placing cast(). Error image is placed at bottom
class ChennaiModel{
final int ra;
final String ci;
final bool lo;
final List<String> ab;
ChennaiModel({
this.ra,this.ci,this.lo,this.ab
});
factory ChennaiModel.fromJson(Map<String,dynamic>parsedjson){
var streetsFromJson = parsedjson['streets'];
List<String> streetsList = streetsFromJson.cast<String>();
return new ChennaiModel(
ra:parsedjson['rank'],
ci:parsedjson['city'],
lo:parsedjson['love'],
ab:streetsList
);
}
}
Future<ChennaiModel> getchennai() async {
final response = await http.get(Uri.https('run.mocky.io','/v3/1496b5ef-873a-48db-9550-75195f2db3b4'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
return ChennaiModel.fromJson(jsonDecode(response.body));
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to load album');
}
}
