Permalink
Browse files

Simpler serializations JSON <=> Object

  • Loading branch information...
1 parent e07ca14 commit 6a660d3147ec954f28480e1ade61ebee613d6730 @MathieuLorber committed Oct 24, 2012
Showing with 13 additions and 4 deletions.
  1. +3 −4 labs/architecture-examples/dart/dart/TodoApp.dart
  2. +10 −0 labs/architecture-examples/dart/dart/app.dart
@@ -26,10 +26,9 @@ class TodoApp {
String jsonList = window.localStorage["todos-vanilladart"];
if(jsonList != null) {
try {
- List<String> todos = JSON.parse(jsonList);
- todos.forEach((String jsonTodo) {
- Map todo = JSON.parse(jsonTodo);
- addTodo(new Todo(todo['id'], todo['title'], Boolean.parse(todo['completed'])));
+ List<Map> todos = JSON.parse(jsonList);
+ todos.forEach((Map todo) {
+ addTodo(new Todo.fromJson(todo));
});
} catch (e) {
window.console.log("Could not load todos form local storage.");
@@ -17,6 +17,16 @@ class Todo {
bool completed;
Todo(String this.id, String this.title, [bool this.completed = false]);
+
+ Todo.fromJson(Map json) {
+ id = json['id'];
+ title = json['title'];
+ completed = json['completed'];
+ }
+
+ Map toJson() {
+ return {'id': id, 'title': title, 'completed': completed};
+ }
}
class UUID {

0 comments on commit 6a660d3

Please sign in to comment.