- class Model {
-
- int key;
- String value;
-
- Model(this.key, this.value);
-
- String toJson() {
- Map<String, dynamic> all = {};
- all["key"] = key;
- all["value"] = value;
- return jsonEncode(all);
- }
-
- static Model fromJson(String jsonData) {
- Map<String, dynamic> all = jsonDecode(jsonData) as Map<String, dynamic>;
- int key = all["key"];
- String value = all["value"];
- return Model(key, value);
- }
-
- }
需要注意的是,map的Key不可以是String以外的类型,不然会报错
Unhandled Exception: Converting object to an encodable object failed: