json_value 0.0.2 json_value: ^0.0.2 copied to clipboard
It's easier to get the value from JSON
JsonValue #
It's easier to get the values from JSON
Getting Started #
Add this to your package's pubspec.yaml file:
dependencies:
easy_json: "^0.0.1"
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",
}
]
}
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'];
}
}
With EasyJSON 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;
You don't worry about array overstepping . It`s safe