Last updated:
0 purchases
json value
JsonValue #
It's easier to get the values from Jaon data
Getting Started #
Add this to your package's pubspec.yaml file:
dependencies:
json_value: "^1.0.0"
copied to clipboard
Why is it not good to get value from json #
if response like this
{
"user":{
"name":"Jack",
"age":20
},
"fruits":[
{
"name":"apple",
"detail":"apple is sweet"
},{
"name":"watermelon",
"detail":"watermelon is full of water",
}
]
}
copied to clipboard
if you want to get user->name ,on the safe side ,you will code like this:
if(response is Map<String,dynamic>){
var user = response['user'];
if (user is Map<String,dynamic>){
var name = user['name'];
}
}
copied to clipboard
With JsonValue all you have to do is:
JsonValue json = JsonValue(response);
var name = json['user']['name'].stringValue;
var fruits = json['fruits'].listValue;
var appleName = json['fruits'][0]['name'].stringValue;
copied to clipboard
You don't worry about array overstepping . It`s safe
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.