【问题标题】:How to Convert response from api using graphQL to Plain Old Dart Object in flutter?如何将使用graphQL的api响应转换为flutter中的Plain Old Dart Object?
【发布时间】:2019-12-11 02:11:22
【问题描述】:

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

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

【问题讨论】:

    标签: flutter dart graphql


    【解决方案1】:

    模型类

    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);
    

    【讨论】:

      猜你喜欢
      • 2022-12-20
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2022-01-08
      • 2020-07-03
      • 2020-10-31
      • 2020-10-04
      相关资源
      最近更新 更多