json_conversion 0.0.4 copy "json_conversion: ^0.0.4" to clipboard
json_conversion: ^0.0.4 copied to clipboard

Automatically generate code for jsonDecode by annotating Dart classes.

Json序列化dart全局统一解析 #

提供json序列化dart统一处理功能,可用于网络请求成功之后的统一解析

使用 添加如下依赖 #

dependencies:
  json_conversion_annotation: ^0.0.4

dev_dependencies:
  build_runner: ^2.0.0
  json_conversion: ^0.0.4

1. 在lib目录下创建一个空dart文件,添加注解,类名随意 example #

@JsonConversionTarget()
class Json{}

2. 在你需要统一处理的实体类里添加@JsonConversion()注解 example #

@JsonConversion()
class UserBean{

  static UserBean jsonConversion(Map<String, dynamic> json) {
    return UserBean();
  }
}

3.运行 flutter pub run build_runner build 命令,就会生成json.jc.dart文件 generated file #

4.如何调用 example #

UserBean userBean = JsonConversion$Json.fromJson<UserBean>(json);

json_conversion #

Provides [Dart Build System] builders for json Unified processing.

Usage #

dependencies:
  json_conversion_annotation: ^0.0.1

dev_dependencies:
  build_runner: ^2.0.0
  json_conversion: ^0.0.1

1.create a empty class in your lib dir example #

@JsonConversionTarget()
class Json{}

2. annotate @JsonConversion() in your bean, and add jsonConversion static method example #

@JsonConversion()
class UserBean{

  static UserBean jsonConversion(Map<String, dynamic> json) {
    return UserBean();
  }
}

3. run 'flutter pub run build_runner build' command to generate file generated file #

4. use example #

UserBean userBean = JsonConversion$Json.fromJson<UserBean>(json);
1
likes
100
pub points
0%
popularity

Publisher

verified publishernewtab.work

Automatically generate code for jsonDecode by annotating Dart classes.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

analyzer, build, flutter, glob, json_conversion_annotation, source_gen

More

Packages that depend on json_conversion