【发布时间】:2020-09-20 12:10:42
【问题描述】:
我有以下两个类,其中一个类从另一个类扩展,如下所示:
@JsonSerializable(nullable: true)
class Response {
final String responseCode;
final String responseMessage;
final String errorLog;
Response({this.errorLog, this.responseCode, this.responseMessage});
factory Response.fromJson(Map<String, dynamic> json) =>
_$ResponseFromJson(json);
}
.................................................. ..........
@JsonSerializable(nullable: false)
class Verify extends Response {
Data data;
Verify({
this.data,
});
factory Verify.fromJson(Map<String, dynamic> json) => _$VerifyFromJson(json);
Map<String, dynamic> toJson() => _$VerifyToJson(this);
}
每当我尝试从验证类中读取 response 类属性时,它始终为空。
那么请问如何实现呢?
【问题讨论】:
-
datacontractjsonserializer 是一个 .NET 组件,可以将 .NET 对象直接序列化为 JSON 数据。由于您使用的是颤振和飞镖,而不是 c# 或任何其他 .Net 语言,我删除了标签。
标签: flutter inheritance dart jsonserializer