Friends, I am in a project where I need to access the information of a fairly complex JSON.
This is the one for the episodes. I need to access the "season", "info" and "episodes" properties but I can't figure out how to do it.
Create the model from quicktype.io and I am using the following parse to access the data:
class SeasonsProvider {
final String url =
'url_api';
Future<List<Season>> cargarTemporadaSerie(serieId) async {
final String urlfinal = url + '${serieId}';
final resp = await http.get(urlfinal);
final Map<String, dynamic> decodedData = json.decode(resp.body);
final List<Season> seasons = new List();
if (decodedData == null) return [];
decodedData.forEach((nombre, season) {
final seasonTemp = Season.fromJson(season);
seasonTemp.name = nombre;
season.add(seasonTemp);
});
return seasons;
} }
The problem is that it does not do a correct conversion of the JSON format and I cannot get the data, I get the following exception.
I need to get a list with the parameter "name"
I solved it with the following code: