I am using the dart package json_serializable for json serialization. Looking at the flutter documentation it shows how to deserialize a single object as follow:
<
You can also Do it like
List< Item > itemsList= List< Item >.from(parsedListJson.map((i) => Item.fromJson(i)));
This is my Model class -
class SuggestedMovie {
String title;
String genres;
int movieId;
SuggestedMovie({this.title, this.genres, this.movieId});
factory SuggestedMovie.fromJson(Map<dynamic, dynamic> parsedJson) {
return SuggestedMovie(
movieId: parsedJson['movieId'],
title: parsedJson['title'] as String,
genres: parsedJson['genres'] as String,
);
}
}
The one below is the code for Deserializing the JSON response into List
suggestedMovie = (json.decode(jsonResponse.data) as List)
.map((i) => SuggestedMovie.fromJson(i))
.toList();