Encode and Decode Json in Dart | Flutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
assalamualaikum where we'll take a look how  to convert a map or json object to a string   import this library dart convert and then  this library has a function json in code   all you need to do pass this map or json  object to this function so it will convert this   map or json object to a string so then we can  use this print statement to print this string so   this is our new string even though it looks  like a map or json but it is actually string   because you can access them one by one even  this curly braces are part of the string for   example we can print the first one by index  and we'll see over here the first curly brace   so as you see we can access any part of the  string using this index for example this time   we can access this n as you can see over here so  this is how using this json encode you convert a   map to a string object so every time you want to  convert a map to a string just use json in code   now that we know how to convert a map to a string  object we'll see how to convert a string to a map   or json object to do that simply you will use  the opposite one json decode now over here we   are passing this string the one we had early  we are passing this map string this string   to json decode function so what it will do  it will convert this string to a map object so as you can see right now we don't have  this double quotes so which means that   it is a map since this json decode returns a map  you can't really access part of it using this   index like we did early for this string so in this  case we'll get null so as you can see but you can   access using their key now over here we do get a  map and if this is a map we can access the value   by key now we see that our first key is  age so we'll simply put the key over here   and now we'll see that we are able  to access the value of this key   so here we see the base tank we can also change it  to age here we'll see 34. so yes when you convert   a string to a json object using json decode you  can access them using the keys not really by   index so that's the basic difference between json  in code and json decode once again json encode   always used to convert a map to a string object  and the json decode is used to convert a string   to a map object so that you can access the map  object using the particular key thank you so much
Info
Channel: dbestech
Views: 13,742
Rating: undefined out of 5
Keywords: dart jsonencode, dart jsondecode, conver json to string, convert string to json, how to convert string to json dart, how to convert json to string dart
Id: 1zq3LjwMh6c
Channel Id: undefined
Length: 2min 59sec (179 seconds)
Published: Thu Apr 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.