All language subtitles for 003 Casting JSON to Model Instances_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bh Bihari
bs Bosnian
br Breton
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
tt Tatar
te Telugu
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

In the last section, we got a better idea of how to work with Jason data that we fetch from some remote

API, but the very end, I mentioned how with Dart we like to have a good idea of the type of data that

we are working with when we retrieve some JSON from some endpoint.

We really don't know what the values that we're going to get back inside that, Jason, are.

So one very common thing that we do is create model classes to give darte a better idea of the type

of data that we expect to get back from this JSON API.

So to get started in creating a model class will first define a class at the bottom of this file.

I'm going to call my class image model because it is essentially a class that's going to model all the

different properties of an image.

Then the two different instance variables that I will assign to this class are going to be the same

instance, variables that are contained inside of my JSON.

So I care about this property.

You are are right here and this is property right here.

You, Earl, is supposed to be a string and it over here is supposed to be an integer.

So I'm going to add an instance variable of Int for ID and for string.

I'll put in a Eurail.

So now we can add in a constructor function that will take in some ID and some URL and create a new

instance of this image model that we can work with.

So I will define my constructor function.

Remember, we can do that by defining a function inside the class with an identical name to the class

itself.

I'll put a semicolon at the end of the line and then we can accept inside of here this dotted as the

first argument in this URL as the second argument.

So now, rather than doing the print statement up here.

I can try to make a new image model instance with a new image model, and then for the first argument,

I will pass in an ID, so I will say past Jason and I'll use the square brackets ID.

And then for the second argument, I'll pass in that you out so fast, Jason, you, Earl.

All right.

I know this line is a little bit tight right there.

So I'm going to zoom out for just a moment so you can see the entire segment of code on one line.

There we go.

So now when we get back, this map of past JSON data will create a new image model instance passing

in our ID and the URL, now that we've got the image model right here, Darte knows exactly what properties

and what types of values it should expect to see on this image model.

So now we could print out, say, image model and we do not have to access our ID or our URL with the

bracket notation anymore.

We can simply use a print image model ID and if we run this, we will again see one appear up here.

There we go.

And of course, I can do your URL as well.

And I get back the out.

OK, I'm going to zoom in just one more time and we're going to look at one additional improvement that

we can make to this.

All right, so nice and big again, so you can see the code more easily.

So all the kids we have right now definitely works, and it definitely gives start a better idea of

the different properties that we expect to get back from our Jason and their different types.

However, you'll notice that whenever we create an instance of the image model right here, we have

to do this very laborious practice of referencing the past, Jason, and then trying to reference some

particular property to pass in.

So I want to make one more improvement to this, and I want to try to make creation of an image model

like we are right here a little bit easier and straightforward than it is right now.

So let's take one more brief pause.

We'll come back to the next section and we'll figure out how we can improve this line of code right

here to be a little bit more concise than it currently is.

So quick break and I'll see you in just a minute.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.