Flutter json parsing | Flutter Parse Json| Parse Complex Json | Nested Json Parsing in flutter | #16

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to my channel this is part 16 of our flutter tutorial series in this part we will learn about json downloading and json passing and flutter so let's start i have this so empty project open and i will create a stateless widget in this now first i will create here the run app method and in this run it method i will create a material [Music] material app and then i will click enter and put a semicolon here now it's outside this curly brace i will type sd less stateless now it will create a stateless widget now i will give the class name as json demo and now i will call this just demo class here as a home in this material now we will override another method called init in its state but before calling united state we will make this uh stateless widget as stateful widget now here down i will call the init state method override it now we will create a new method here at the top get json data and this type will be wide which means it will return nothing and we will make this async so it will ascend chronologically download json data for us now i need a library called http that is available in uh flutter so the latest version of http is uh this zero point one two point two and i will copy it from here copy the text from here or you can copy it from the here directly and then put that colon and and i will come to this uh prospect dot yml file and here down in this dependencies section i'll find the dependencies section this is the dependency section this one and i will paste it here control v this and now we have the latest version uh 0.2.1 0.12.2 so i will change it to 0.12.2 and i will upgrade this to download the dependencies now it is uh showing us an error because this is not in sand line with this that is why it is showing this error now if i forget it it will successfully download this dependency now the dependency is successfully set up so i will go to main.file and i'll go to the top and import package http dot dot and now i'll come to this uh and i will go here and response response equal to get and here i will pass the url from which i will download the json so i'll come here and i will type here json placeholder i'll paste this url in the description of the video if you want to test it now i will download this user data now i will copy this api and now i'll come here and control it here now put it inside single quotes or double quotes whatever you want and now it will start showing an error because we have not used the event keyword before this gate now when it download the json data it will be available inside this response so we will print response dot body and we will see in the console that if it is printing anything now i will come to this uh um this init state method and i will call git json data method here semicolon now everything is set up let's run the application and let's see if it is working now i will run this now if we look to the console it has unloaded the data the json data and it has printed it in the console we can see it here now i will go to the browser and if we look at this json the first element of this json is adjacent array which is a square bracket a square bracket represent adjacent array so i'll come to this and i will go to this uh get data method and now we will change this json data now first i need a an import that will convert this json data for me dot convert now i'll come here to get json and now in flutter adjacency array is considered as list so i call less data because the first element is adjacent array if it was just an object then we would use a map because an adjacent object object is represented by a map in flutter and an array by list so i will json the code and response dot body so it will automatically decode this uh json data into a list now then if we look at this json we have multiple json object inside this json array so i can get it by using for loop because in this array we have 10 json objects different json object so by for loop i will get all of these json objects so i'll come here and use data door for each view i will use for now i'll click enter and use a semicolon here and i'll come here and make this map of the j is equal to element now every element is adjacent object so we assign mac to it now i will get each string from this obj so i i'll use string is equal to obj and square brackets and now with single chords i would use uh consider i want to get this name so name and here i will put semicolon and now i have not given a name to its word give it name and now i am printed here and we will see that if we are getting this name semicolon and now i will run the application on the device now you can see that it has loaded the names and printed in the console all 10 names now if i go to this json and look at it this address i can [Music] retrieve this username email and this id by the same method but this uh address is a json object again so how can i retrieve uh it and uh then get the data inside it so i'll go to [Music] android studio and remove this and now i will say map address is equal to obj and then square brackets and then address semicolon and now i will get a string value from this address string now what i want to get from this street consider i want to get the street so sd or double each is equal to address square brackets and straight and now put semicolon and this run the application how to start it now we have made one mistake that we have not printed the street so i'll print street and semicolon and now i will not start it again now you can see that the streets uh are also retrieved if you look at this and you uh certified street coalesce light and here and the second series is victor plans and now if i come to this android studio so you can see the street are retrieved now if we look at the json here we have this jio another just an object so which can be represented by by map so i will come to this and let's retrieve this as well so this is in the address so map jio is equal to address and now square brackets and inside this i will use geo and now for semicolon semi for them and now i will uh let's see what type so it is strength so strength rate is equal to geo and then i will retribulate semicolon same column and now i will print lead semicolon and now let's run this how to start this now you can see that the latitude of every user is printed so that's all for today i hope you like the video and this way you can pass complex jsons in flutter so that's all for today i hope you liked the video if you like the video please subscribe to my channel as well as like and comment because i need your love and support to grow this channel thank you
Info
Channel: Programming Guru
Views: 12,689
Rating: undefined out of 5
Keywords: flutter json decode array, parse nested json objects in flutter, flutter json parsing, complex json flutter, parse complex json flutter, parsing json in flutter, flutter parse json, Flutter json array to list, json parsing in flutter, json parsing in flutter example, json decode in flutter, complex json parsing in flutter, nested json parsing in flutter, parse json object in flutter, Json decode flutter, fetch data from api in flutter, flutter json, json flutter
Id: 3vUxfK4pL70
Channel Id: undefined
Length: 15min 51sec (951 seconds)
Published: Fri May 06 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.