【发布时间】:2019-06-07 22:03:09
【问题描述】:
我有一个名为 FullTrip 的 Main 类,这个类具有称为 itineraries 的属性,其他包含两条数据
所以我创建了另一个名为 Hc 的类,现在我需要使用这种组合来解析来自服务器的 json 响应
class FullTrip extends Trip{
final List<String> including;
final List<String> excluding;
final List<Hc> itineraries;
final List<Hc> policies;
FullTrip(this.including,this.excluding,this.itineraries,this.policies,int id,String title,double price,String overview,String hero_image):
super(id:id,title:title,price:price,overview:overview,hero_image:hero_image);
factory FullTrip.fromJson(Map<String, dynamic> json) =>
_$FullTripFromJson(json);
}
class Hc {
final String head;
final String content;
Hc({this.head,this.content});
}
当我使用这样的代码并运行序列化命令时
flutter packages pub run build_runner build --delete-conflicting-outputs
终端出错
[严重] lib/models/fulltrip.dart 上的 json_serializable:运行时出错 JsonSerializableGenerator 无法生成
fromJson代码itineraries因为类型Hc。没有提供TypeHelper实例支持定义的类型。 package:Tourism/models/fulltrip.dart:21:18 最终名单 行程; ^^^^^^^^^^^ [警告] lib/models/fulltrip.dart 上的 json_serializable:缺少“part 'fulltrip.g.dart';”。 [信息] 运行构建完成,耗时 3.0s[INFO] 缓存最终确定的依赖图... [INFO] 缓存最终确定 依赖图完成,耗时 68ms
【问题讨论】: