how do make a 'Model' with a Json structure like this?
--
beforely, I tried parsing json in another form and it worked, and when I tried to make the structure for json above like this:
class HomeTeam {
final int id, legacyId, name, countryId;
final bool nationalTeam;
final String logoPath;
HomeTeam({this.id, this.legacyId, this.name, this.countryId, this.nationalTeam, this.logoPath});
factory HomeTeam.fromJson(Map<String, dynamic> json){
return HomeTeam(
id: json['id'],
legacyId: json['legacy_id'],
name: json['name'],
nationalTeam: json['national_team'],
logoPath: json['logo_path']
);
}
}
.
homeTeam: HomeTeam.fromJson(json['localTeam']['data']),
Then the result appears an error..
NoSuchMethodError: The method '[]' was called on null. E/flutter (
220): Receiver: null E/flutter: Tried calling:
how to solve this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…