阅读 164

Flutter 关于Json生成插件点评

测试模板数据

{"page":88,"value":8.8,"isNonProfit":true,"address":{"address":{"address":{"address":{"field":"value"},"field":"value"}},"field":"value"},"links":[[[[{"name":"SoSo","url":"http://www.SoSo.com"}]]]]}
复制代码

JsonToDart

JsonToDart (JSON To Dart) - Plugins | JetBrains

评分4.5 下载36395;作者:Ankit Mahadik

测试效果

class JD {
  int _page;
  double _value;
  bool _isNonProfit;
  Address _address;
  List<List<List<List<Links>>>> _links;

  int get page => _page;

  double get value => _value;

  bool get isNonProfit => _isNonProfit;

  Address get address => _address;

  List<List<List<List<Links>>>> get links => _links;

  JD(
      {int page,
      double value,
      bool isNonProfit,
      Address address,
      List<List<List<List<Links>>>> links}) {
    _page = page;
    _value = value;
    _isNonProfit = isNonProfit;
    _address = address;
    _links = links;
  }

  JD.fromJson(dynamic json) {
    _page = json["page"];
    _value = json["value"];
    _isNonProfit = json["isNonProfit"];
    _address =
        json["address"] != null ? Address.fromJson(json["address"]) : null;
    if (json["links"] != null) {
      _links = [];
      json["links"].forEach((v) {
        _links.add(Links.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["page"] = _page;
    map["value"] = _value;
    map["isNonProfit"] = _isNonProfit;
    if (_address != null) {
      map["address"] = _address.toJson();
    }
    if (_links != null) {
      map["links"] = _links.map((v) => v.toJson()).toList();
    }
    return map;
  }
}
......
复制代码
  • 优点:
  • 缺点:生成嵌套json有bug

Json2Dart

Json2Dart - Plugins | JetBrains

  • 优点:
  • 缺点:生成嵌套json有bug,不区分int,double

FlutterJsonBeanFactory

FlutterJsonBeanFactory - Plugins | JetBrains

测试效果

class FlutterJsonBeanFactoryBean with JsonConvert<FlutterJsonBeanFactoryBean> {
	int page;
	double value;
	bool isNonProfit;
	FlutterJsonBeanFactoryAddress address;
	List<List> links;
}

class FlutterJsonBeanFactoryAddress with JsonConvert<FlutterJsonBeanFactoryAddress> {
	FlutterJsonBeanFactoryAddressAddress address;
	String field;
}

class FlutterJsonBeanFactoryAddressAddress with JsonConvert<FlutterJsonBeanFactoryAddressAddress> {
	FlutterJsonBeanFactoryAddressAddressAddress address;
}

class FlutterJsonBeanFactoryAddressAddressAddress with JsonConvert<FlutterJsonBeanFactoryAddressAddressAddress> {
	FlutterJsonBeanFactoryAddressAddressAddressAddress address;
	String field;
}

class FlutterJsonBeanFactoryAddressAddressAddressAddress with JsonConvert<FlutterJsonBeanFactoryAddressAddressAddressAddress> {
	String field;
}

class FlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLink with JsonConvert<FlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLinkFlutterJsonBeanFactoryLink> {
	String name;
	String url;
}
复制代码

评分4.8 下载148510

  • 优点:
  • 缺点:生成嵌套json有bug,使用了runtimeType.toString(),则没法使用Dart混淆。集中式管理,维护一个大文件大类JsonConvert,对修改不友好

Json2DartBean

没错我就是来王婆卖瓜的🍉🍉🍉,本瓜嫁接于Json2Dart(很久都不更新了)

Json2DartBean - Plugins | JetBrains

  • 优点:可生成嵌套json,统一配置其父类和导包及生成类的尾缀
  • 缺点:你说我改
文章分类
Android
文章标签