Created
June 13, 2013 08:58
-
-
Save samiy-xx/5772273 to your computer and use it in GitHub Desktop.
quickie
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:json' as json; | |
class CartItem { | |
int id; | |
String name; | |
String category; | |
CartItem(this.id, this.name, this.category); | |
Map toJson() { | |
return { | |
'id': id, | |
'name': name, | |
'category': category | |
} | |
} | |
static CartItem fromMap(Map m) { | |
return new CartItem(m['id'], m['name'], m['category']); | |
} | |
} | |
List<CartItem> items = new List<CartItem>(); | |
items.add(new CartItem(0, "Banana", "food")); | |
items.where((CartItem item) => item.category == "food").forEach((CartItem item) => print(item.name)); | |
//stringify object: | |
json.stringify(yourObject.toJson()); | |
// parse object | |
CartItem item = CartItem.fromMap(json.parse(STRING_JSON_FROM_SERVER)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment