【发布时间】:2019-02-26 11:15:21
【问题描述】:
我正在尝试将 json 支持添加到我的颤振项目中,但很难做到正确。
我喜欢颤振,但说到 json,我希望使用 gson。
我创建了一个小项目来说明我的问题。
请关注https://bitbucket.org/oakstair/json_lab
我得到了错误 在尝试运行简单的 to/from json 测试时,类型 'Match' 不是类型转换中类型 'Map' 的子类型。
这里显然有一些我想念的东西!
提前感谢暴风雨的斯德哥尔摩!
import 'package:json_annotation/json_annotation.dart';
part 'json_lab.g.dart';
@JsonSerializable()
class Match {
int home;
int away;
double homePoints;
double awayPoints;
Match(this.home, this.away, {this.homePoints, this.awayPoints});
factory Match.fromJson(Map<String, dynamic> json) => _$MatchFromJson(json);
Map<String, dynamic> toJson() => _$MatchToJson(this);
}
@JsonSerializable()
class Tournament {
List<String> participants; // Teams or Players.
List<List<Match>> table = new List<List<Match>>();
Tournament(this.participants, {this.table});
factory Tournament.fromJson(Map<String, dynamic> json) => _$TournamentFromJson(json);
Map<String, dynamic> toJson() => _$TournamentToJson(this);
}
【问题讨论】:
-
你能提供你打算接收的json样本吗?
标签: json flutter json-deserialization jsonserializer