如何将使用graphQL的api中的响应转换为flutter中的Plain Old Dart对象?

时间:2019-08-02 12:36:55

标签: flutter dart graphql

我正在尝试将Json转换为PODO(Dart模型类),但出现以下错误:

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
FormatException: Unexpected character (at character 2)

1 个答案:

答案 0 :(得分:0)

模型类

class FormModel {
  final String id;
  final String name;

  FormModel({this.id, this.name});

  factory FormModel.fromJSON(dynamic data) {
    return FormModel(id: data["id"], name: data["name"]);
  }
}

通过JSON创建对象

FormModel form = FormModel.fromJSON(jsonData);