Constructing MovieModel
In this lesson, you'll learn to create a MovieModel object from a JSON formatted API response.
We'll cover the following...
Introduction
In this lesson, we’ll create a MovieModel
Dart class to parse the JSON response returned from API.
MovieModel
class will have properties for each of the data['results']
JSON attributes returned as API response.
Revisiting TMDB API response structure
The JSON response returned from TMDB API looks like a huge blob of string. It could be hard to access the attributes by calling their names every time from code. A spelling mistake can make debugging very hard.
To avoid this problem, it makes sense to create a Dart object mapped to the response. We will call this class MovieModel
.
Earlier, if you would want to access the “title” of the movie, you had to do data['results']['title']
. ...