Created
January 16, 2019 01:07
-
-
Save ericgrandt/e7a7b9315959d3cec0c44ab0bf0a3a2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
User userFromJson(String str) { | |
final jsonData = json.decode(str); | |
return User.fromJson(jsonData); | |
} | |
String userToJson(User data) { | |
final dyn = data.toJson(); | |
return json.encode(dyn); | |
} | |
class User { | |
int id; | |
String name; | |
User({ | |
this.id, | |
this.name, | |
}); | |
factory User.fromJson(Map<String, dynamic> json) => new User( | |
id: json["id"], | |
name: json["name"], | |
); | |
Map<String, dynamic> toJson() => { | |
"id": id, | |
"name": name, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment