Reputation: 785
Actually, I am using the traditional way to work with Json:
factory MyObject.fromJson(Map<String, dynamic> json)
I have a lot of objects dealing with Json and over time, I encounter problems like:
Converting object to an encodable object failed: Instance of 'MyObject'#0
I am looking for the best way (external plugin or something else) to manipulate these Json.
Upvotes: 0
Views: 51
Reputation: 422
This is how I would set up the MyObject class to parse Json
class MyObject {
String value;
MyObject({this.value});
static MyObject fromMap(Map<String,dynamic> map){
var value = map['value'];
return MyObject(value:value);
}
}
Upvotes: 1
Reputation: 3315
Take a look on json_serializable package.
And docs has an excellent resource about JSON serialization.
Upvotes: 1