美文网首页
flutter \ dart在json_serializable

flutter \ dart在json_serializable

作者: popesa | 来源:发表于2021-10-19 14:20 被阅读0次
* Use `JsonConverter`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
* Set `JsonSerializable.genericArgumentFactories` to `true`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/genericArgumentFactories.html

以上提示了三种方式。
第一种:使模型类继承JsonConverter。

第二种:使用注解@JsonKey和方法fromJsontoJson

第三种:在注解@JsonSerializable中设置参数genericArgumentFactories为true。

相关文章

网友评论

      本文标题:flutter \ dart在json_serializable

      本文链接:https://www.haomeiwen.com/subject/rzdaoltx.html