简体   繁体   English

将 JSON 数据转换为模型类 Flutter

[英]Converting JSON data to model class Flutter

I want to convert JSON data to model class, I used this https://javiercbk.github.io/json_to_dart/ but I am not getting what I want, can you please assist.我想将 JSON 数据转换为模型类,我使用了这个https://javiercbk.github.io/json_to_dart/但我没有得到我想要的,请你帮忙。

My JSON data我的 JSON 数据

[
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 11,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "AdjustedValues",
        "Value": [],
        "ServiceResponsePropertyId": 474,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 11,
        "CategoryId": 1,
        "Category": "General",
        "Description": "ServiceStatus",
        "Value": {
            "StatusCode": 1,
            "StatusDescription": "Ok",
            "StatusDetail": "",
            "RestServiceStatus": null,
            "ServiceResource": null
        },
        "ServiceResponsePropertyId": 475,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "CarId",
        "Value": 120354,
        "ServiceResponsePropertyId": 100,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Year",
        "Value": 2017,
        "ServiceResponsePropertyId": 103,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 6
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Full Model Description",
        "Value": "2017 AUDI A3 Sedan 1.0T FSI S tronic [2016-2017]",
        "ServiceResponsePropertyId": 104,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Model",
        "Value": "A3 Sedan 1.0T FSI S tronic [2016-2017]",
        "ServiceResponsePropertyId": 105,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 5
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "ImageUrl",
        "Value": "https://cdn.lightstoneauto.co.za/PHOTOS/AUDI/120354_1_Z7.jpg",
        "ServiceResponsePropertyId": 107,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Make",
        "Value": "AUDI",
        "ServiceResponsePropertyId": 110,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 3
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Type",
        "Value": "AUDI A3 Sedan",
        "ServiceResponsePropertyId": 111,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 4
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 6,
        "CategoryId": 1,
        "Category": "General",
        "Description": "ServiceStatus",
        "Value": {
            "StatusCode": 1,
            "StatusDescription": "Ok",
            "StatusDetail": "",
            "RestServiceStatus": null,
            "ServiceResource": null
        },
        "ServiceResponsePropertyId": 125,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 7,
        "CategoryId": 1,
        "Category": "General",
        "Description": "ServiceStatus",
        "Value": {
            "StatusCode": 1,
            "StatusDescription": "Ok",
            "StatusDetail": "",
            "RestServiceStatus": null,
            "ServiceResource": null
        },
        "ServiceResponsePropertyId": 126,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 9999
    },
    {
        "CarId": 0,
        "SpecCategory": "General",
        "Id": -1,
        "SourceId": -1,
        "ServiceId": 7,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Body shape",
        "Value": "Sedan",
        "ServiceResponsePropertyId": 320,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 9999
    },
    {
        "CarId": 0,
        "SpecCategory": "General",
        "Id": -6,
        "SourceId": -6,
        "ServiceId": 7,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Drive type",
        "Value": "4x2",
        "ServiceResponsePropertyId": 154,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 9999
    },
    {
        "CarId": 0,
        "SpecCategory": "General",
        "Id": -7,
        "SourceId": -7,
        "ServiceId": 7,
        "CategoryId": 1,
        "Category": "General",
        "Description": "Fuel type",
        "Value": "Petrol",
        "ServiceResponsePropertyId": 153,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 9999
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "LastFiveSales",
        "Value": [
            {
                "SaleId": 698229,
                "CarId": 120354,
                "SaleYear": 2017,
                "SaleDateTime": "2022-06-09T15:30:38Z",
                "SalePrice": 299900.0,
                "MunicipalityName": "CITY OF TSHWANE",
                "Id": 0,
                "SourceId": 0,
                "ServiceId": 0,
                "CategoryId": 0,
                "Category": null,
                "Description": null,
                "Value": null,
                "ServiceResponsePropertyId": 0,
                "MappingId": 1,
                "IsVisible": false,
                "PackageRequestId": 0,
                "SortOrder": 0
            },
            {
                "SaleId": 695530,
                "CarId": 120354,
                "SaleYear": 2017,
                "SaleDateTime": "2022-05-30T13:24:17Z",
                "SalePrice": 289995.0,
                "MunicipalityName": "CITY OF TSHWANE",
                "Id": 0,
                "SourceId": 0,
                "ServiceId": 0,
                "CategoryId": 0,
                "Category": null,
                "Description": null,
                "Value": null,
                "ServiceResponsePropertyId": 0,
                "MappingId": 1,
                "IsVisible": false,
                "PackageRequestId": 0,
                "SortOrder": 0
            },
            {
                "SaleId": 685020,
                "CarId": 120354,
                "SaleYear": 2017,
                "SaleDateTime": "2022-04-14T12:27:37Z",
                "SalePrice": 366948.0,
                "MunicipalityName": "EMFULENI",
                "Id": 0,
                "SourceId": 0,
                "ServiceId": 0,
                "CategoryId": 0,
                "Category": null,
                "Description": null,
                "Value": null,
                "ServiceResponsePropertyId": 0,
                "MappingId": 1,
                "IsVisible": false,
                "PackageRequestId": 0,
                "SortOrder": 0
            },
            {
                "SaleId": 683843,
                "CarId": 120354,
                "SaleYear": 2017,
                "SaleDateTime": "2022-04-11T15:00:38Z",
                "SalePrice": 315500.0,
                "MunicipalityName": "UMHLATHUZE",
                "Id": 0,
                "SourceId": 0,
                "ServiceId": 0,
                "CategoryId": 0,
                "Category": null,
                "Description": null,
                "Value": null,
                "ServiceResponsePropertyId": 0,
                "MappingId": 1,
                "IsVisible": false,
                "PackageRequestId": 0,
                "SortOrder": 0
            },
            {
                "SaleId": 652718,
                "CarId": 120354,
                "SaleYear": 2017,
                "SaleDateTime": "2022-04-01T11:53:45Z",
                "SalePrice": 339900.0,
                "MunicipalityName": "CITY OF TSHWANE",
                "Id": 0,
                "SourceId": 0,
                "ServiceId": 0,
                "CategoryId": 0,
                "Category": null,
                "Description": null,
                "Value": null,
                "ServiceResponsePropertyId": 0,
                "MappingId": 1,
                "IsVisible": false,
                "PackageRequestId": 0,
                "SortOrder": 0
            }
        ],
        "ServiceResponsePropertyId": 481,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 0
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "ServiceStatus",
        "Value": {
            "StatusCode": 1,
            "StatusDescription": "Ok",
            "StatusDetail": "",
            "RestServiceStatus": null,
            "ServiceResource": null
        },
        "ServiceResponsePropertyId": 482,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 13818024,
        "SortOrder": 0
    },
    {
        "EstimateType": "Auction",
        "CarId": 0,
        "Id": 1,
        "SourceId": 1,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Auction Estimate",
        "Value": 189400.0,
        "ServiceResponsePropertyId": 494,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "EstimateType": "Cost",
        "CarId": 0,
        "Id": 2,
        "SourceId": 2,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Cost Estimate",
        "Value": 238300.0,
        "ServiceResponsePropertyId": 495,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "EstimateType": "Cost",
        "CarId": 0,
        "Id": 3,
        "SourceId": 3,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Cost Estimate High",
        "Value": 259800.0,
        "ServiceResponsePropertyId": 496,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 3
    },
    {
        "EstimateType": "Cost",
        "CarId": 0,
        "Id": 4,
        "SourceId": 4,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Cost Estimate Low",
        "Value": 218700.0,
        "ServiceResponsePropertyId": 497,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 2
    },
    {
        "EstimateType": "Retail",
        "CarId": 0,
        "Id": 5,
        "SourceId": 5,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Retail Estimate",
        "Value": 300800.0,
        "ServiceResponsePropertyId": 498,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "EstimateType": "Retail",
        "CarId": 0,
        "Id": 6,
        "SourceId": 6,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Retail Estimate High",
        "Value": 327900.0,
        "ServiceResponsePropertyId": 499,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 3
    },
    {
        "EstimateType": "Retail",
        "CarId": 0,
        "Id": 7,
        "SourceId": 7,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Retail Estimate Low",
        "Value": 276000.0,
        "ServiceResponsePropertyId": 500,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 2
    },
    {
        "EstimateType": "Trade",
        "CarId": 0,
        "Id": 8,
        "SourceId": 8,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Trade Estimate",
        "Value": 261300.0,
        "ServiceResponsePropertyId": 501,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 1
    },
    {
        "EstimateType": "Trade",
        "CarId": 0,
        "Id": 9,
        "SourceId": 9,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Trade Estimate High",
        "Value": 284900.0,
        "ServiceResponsePropertyId": 502,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 3
    },
    {
        "EstimateType": "Trade",
        "CarId": 0,
        "Id": 10,
        "SourceId": 10,
        "ServiceId": 12,
        "CategoryId": 5,
        "Category": "Valuation",
        "Description": "Trade Estimate Low",
        "Value": 239800.0,
        "ServiceResponsePropertyId": 503,
        "MappingId": 0,
        "IsVisible": true,
        "PackageRequestId": 13818024,
        "SortOrder": 2
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 11,
        "CategoryId": 7,
        "Category": "Report",
        "Description": "ReportUrl",
        "Value": "https://pdf.lightstoneauto.co.za/Index.aspx?sourceurl=https://cdn.lightstoneauto.co.za/REPORTS/LIVE/ba22673b-0f05-4ae9-b212-0369a7c793ad.html",
        "ServiceResponsePropertyId": 0,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 0,
        "SortOrder": 0
    },
    {
        "Id": 0,
        "SourceId": 0,
        "ServiceId": 11,
        "CategoryId": 7,
        "Category": "Report",
        "Description": "HtmlUrl",
        "Value": "https://cdn.lightstoneauto.co.za/REPORTS/LIVE/ba22673b-0f05-4ae9-b212-0369a7c793ad.html",
        "ServiceResponsePropertyId": 0,
        "MappingId": 0,
        "IsVisible": false,
        "PackageRequestId": 0,
        "SortOrder": 0
    }
]

I want to show only type "Value" on the UI, so can anyone assist on how can I create the model class with this json data then show the "Value" on a list or text so can anyone please help on how do I go about this??我只想在 UI 上显示类型“值”,所以任何人都可以帮助我如何使用这个 json 数据创建模型类,然后在列表或文本上显示“值”,所以任何人都可以帮助我如何去对这个?? I have stuck for a while now.我已经坚持了一段时间了。 Your help will be appreciated, thanks in advance.您的帮助将不胜感激,在此先感谢。

    class DartClass {
  int? id;
  int? sourceId;
  int? serviceId;
  int? categoryId;
  String? category;
  String? description;
  dynamic value;
  int? serviceResponsePropertyId;
  int? mappingId;
  bool? isVisible;
  int? packageRequestId;
  int? sortOrder;

  DartClass(
      {this.id,
      this.sourceId,
      this.serviceId,
      this.categoryId,
      this.category,
      this.description,
      this.value,
      this.serviceResponsePropertyId,
      this.mappingId,
      this.isVisible,
      this.packageRequestId,
      this.sortOrder});

  DartClass.fromJson(Map<String, dynamic> json) {
    id = json['Id'];
    sourceId = json['SourceId'];
    serviceId = json['ServiceId'];
    categoryId = json['CategoryId'];
    category = json['Category'];
    description = json['Description'];
    value = json['Value'];
    serviceResponsePropertyId = json['ServiceResponsePropertyId'];
    mappingId = json['MappingId'];
    isVisible = json['IsVisible'];
    packageRequestId = json['PackageRequestId'];
    sortOrder = json['SortOrder'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data =  {};
    data['Id'] = id;
    data['SourceId'] = sourceId;
    data['ServiceId'] = serviceId;
    data['CategoryId'] = categoryId;
    data['Category'] = category;
    data['Description'] = description;
    data['Value'] = value;
    data['ServiceResponsePropertyId'] = serviceResponsePropertyId;
    data['MappingId'] = mappingId;
    data['IsVisible'] = isVisible;
    data['PackageRequestId'] = packageRequestId;
    data['SortOrder'] = sortOrder;
    return data;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在控制器上将json数据转换为模型时出错 - error on Converting json data to model at controller 使用子Collection将JSON数据转换为Backbone Model - Converting JSON data to Backbone Model with child Collection 在颤振中使用 Chopper 库将 JSON 响应转换为模型对象? - Converting JSON response to Model Object using Chopper library in flutter? 我正在尝试将 Json 数据转换为 model class 在 ZC047B10EEE71CC268 但我收到“Flutter FormatException:意外字符”错误 - I'm trying to prase the Json data to model class in Flutter. but i'm getting "Flutter FormatException: Unexpected character" Error 如何在 Flutter 上的 Firestore 中序列化/建模模型 json 数据 - How to serialize/model inside model json data from Firestore on Flutter 将 .model 文件转换为 .Json - Converting .model file to .Json 将 ODataModel 转换为 JSON 模型 - Converting ODataModel into JSON Model 如何从 JSON 响应 Map Model Class Flutter/MongoDB - How to Map Model Class from JSON Response Flutter/MongoDB 如何将 json 数组转换为 model class in flutter dart/ - How to convert json array to model class in flutter dart/ 如何从 Flutter 中的复杂 json 数据 model 中检索数据 - How to retrieve data from a complicated json data model in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM