flutter \ dart在json_serializable

2021-10-19  本文已影响0人  popesa
* 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。

上一篇 下一篇

猜你喜欢

热点阅读