I' trying to parse this type of json :
"teams": [
{
"id": 1,
"name": "New Jersey Devils",
"link": "/api/v1/teams/1",
"venue": {
"name": "Prudential Center",
"link": "/api/v1/venues/null",
"city": "Newark",
"timeZone": {
"id": "America/New_York",
"offset": -4,
"tz": "EDT"
}
},
"abbreviation": "NJD",
"teamName": "Devils",
"locationName": "New Jersey",
"firstYearOfPlay": "1982",
"division": {
"id": 18,
"name": "Metropolitan",
"nameShort": "Metro",
"link": "/api/v1/divisions/18",
"abbreviation": "M"
}.........
But I only want the 'id' and 'name' attribute.
Here's my model :
class TeamDetail{
final int id;
final String name;
TeamDetail({this.id, this.name});
factory TeamDetail.fromJson(Map<String, dynamic> json){
return TeamDetail(
id: json["id"],
name: json["name"],
);
}
}
And my method:
Future<TeamDetail> getTeamDetail() async{
final response = await http.get('https://statsapi.web.nhl.com/api/v1/teams/1');
if(response.statusCode == 200){
return TeamDetail.fromJson(json.decode(response.body));
}else{
throw Exception("Failed to load");
}
}
But when I call the method, I always receive a null value. Can you help me please. Thank you
