Welcome back and the last movie you saw how to download data from the Internet and then displayed in
this case, it was just Jason Object, which contains a bunch of text, right?
It's just a text file, so to speak.
But now let's look at how we can deconstruct this whole JSON object.
All right.
Let's go ahead and do that in here.
So, first of all, I need to create adjacent objects.
So while Jason Object is going to be a JSON object object and you can pass in a string here, which
is all result, which is this huge string that we saw in our Lockette.
OK, so this message and so forth, this thing here.
OK, now this chasten object will now understand the structure of it and now we can access elements
from that Jason object.
So I can just go ahead and say I want to have the message which will be JSON object, dot opt string
of our message.
So if we look at substring returns to value met by code name, so whatever we entered as name if it
exists, coercing it if necessary for the empty string if no such mapping exists.
So in our case, if we look at our Lochhead result, we can see that such a message in fact exists.
So this year is the name that we pass to our strength to this method here, and then it will return
the value of it.
So we pass on the key and then we get the value.
OK, so now this message, I will just log that to my console and let's just see if that's actually
going to work.
OK, so let's go to our Lochhead and see if something like message exists.
OK, so we have here a message you have successfully logged in.
All right, so that worked.
So now we can access elements from our Jason object.
So that's how easy it is.
Of course, you can now go ahead and do the same thing with the user ID and all of the other objects.
Right.
So the.
Name and so forth, OK, so whatever the name is going to be in our trace, an object here, whatever
the name here is.
So if we look at our Lochhead again, you can see there is a name in my case, it's planetaria and so
forth.
OK, so you can get all of those values and you can see each time you have to search for the specific
name of the key.
OK, so in a key value pair, but what if there is an actual Chazen object in there?
So if we look at it again, we can see that we have this adjacent object.
This is this whole thing.
And in there we have another JSON objects, which is this profile detail.
So this year is adjacent object.
So if we want to get the JSON object, well, we can use the following approach.
So we saw that we can get strings and we can get INTs because the user ID, as you know, is an integer.
Right.
But we can also get UPT Jason objects.
So just going to create another full profile detail object.
So I'm going to call it and it will just be a JSON object.
Thought about Jason object.
And what's the name of it, what's the name of the string?
Well, let's look at the Lochhead here again.
It was called profile details, so let's paste that in here, profile details and now let's use that.
So Voll is profile completed will be the profile details object out.
And now what do we have there?
We had a boolean so opt boolean.
And what's the name of the boolean.
Well, his profile completed.
And now let's look them so that this lock that I is.
Profile completed, and then we're just going to use this as profile completed value that we prepared
here.
OK, so that is how you can access an object with use of type Jason or Jason object within adjacent
object.
OK, you can still access it via its key, which is in this case, profile details.
And then you can just use this opt JSON object method in order to get it by its name or by its key,
so to speak.
And then we have another very important and interesting aspect here, which is a list.
So you can see here we have a list of jasen objects.
So how do we get that?
Well, we get that by using an opt Jason Array, so while detat list array.
Some call it and it's going to use Jason Object again and get over here.
It's actually about Jason Array.
And now what's the name of the Jason Array again, go here and see.
It's called data list in my example.
All right, so here we use data list and all.
I can use the data array to access its parameters, for example.
So if I want to know the size of the array, so how many entries are in there, I can just go ahead
and say total list array at length so it can just.
Display that in the lock, but then if I want to know about every single value in there, so every single
entry, then it's a little more complicated.
So here I use a for loop for item in zero until detat list array thought length.
So I want to go through the whole list and I start at zero and I go to whatever the amount of entries
are in there and here I can access the individual element.
By using data, risk the line item, but then this item will be a object, right?
So I need to get that as a jasen object again.
So I'm just going to say data item object, which will be adjacent object.
And I get that from they tell us the red dot or actually here item.
As Jason object, and this, of course, is a variable.
OK, so this is how you can now create an object out of whatever was inside of the list or diskettes
its adjacent object.
Right.
So that list array item will be first this chasten object and it will be this chasten object and it
will be destroyed as an object and so forth.
So now we have to do the same thing with every single data item object as we've done before with those
adjacent objects here.
So now we can get it string's it's in.
It's whatever we have in there.
OK, so in this case, we have an ID, which is an integer, then we have a string, which is disvalue
here.
So in order to Eco-System, you can of course pause the video and try to do that yourself.
So pause it and try.
OK, let's try to exercise the idea, so I'm just going to say, well, ID is equal to data item object,
dot opt in and it was called ID.
And now to make sure that it's really an integer, you can see it's a number without the.
Exclamation points here are exclamation marks.
OK, so.
Now, let's lock the ID log that I I.D. is going to be message will be, Heidi.
Now, let's do the same thing with a value.
So full value is a data item, object, dot, opt string this time.
And what's the name of it?
It was value.
So that's the key.
And then we can go ahead and lock that as well.
So log that.
I want the value being the.
Value now let's test it again and see if we actually get those different values and ideas out in our
Lockette.
So let's search for them, let's search for, for example, value.
And you can see value zero was the idea one, value one.
And to value itself is one you can see it totally works.
Now let's say we want to want to have the ID and we are so ID.
One, two, three.
All right.
So now you know how to pull everything apart.
So how to read Jason objects and use them as Jason objects.
So this is super powerful stuff and it will come in handy so many times, believe me.
Now, there is one thing that you might have wondered from the start.
Why do I call this one call API log async task?
Because I'm not logging in or anything like that.
And how would I even login?
Well, in order to login, you need to send a post request to the website, whichever you are using
right.
To the service that you're using.
And in our case, we're not doing that yet.
And that's what we're going to look at in the next video, because then we will need the username and
password in order to log in and in order to then, of course, sent this information to the website
and the website will then.
In our case, do nothings, so unfortunately, we won't be able to test that yet, but we will see you
later on once we are to firebase example how that will come in handy.
But I think it still makes sense to also talk about it here while we are already working with API calls
and everything.
All right.
So see you in the next video.