【发布时间】:2021-07-10 14:47:12
【问题描述】:
我正在使用 json_serializable 将 Map<dynamic, dynamic> 解析为我的对象。
示例:
@JsonSerializable()
class Todo {
String title;
bool done;
Todo(this.title, this.done);
factory Todo.fromJson(Map<String, dynamic> json) => _$TodoFromJson(json);
}
因为我从 api 获得 'done': 1,所以我收到以下错误:
Unhandled Exception: type 'int' is not a subtype of type 'bool' in type cast
如何使用 json_serializable 投射 1 = true 和 0 = false?
【问题讨论】:
标签: json flutter dart serialization