'how to convert json to model class in dart like following image. It have digits of keyvalue header

the app.quicktype.io cannot convert. they are converting and skip the digit class name

class ScoreCardModel {
  bool? status;
  String? msg;
  Data? data;

  ScoreCardModel({this.status, this.msg, this.data});

  ScoreCardModel.fromJson(Map<String, dynamic> json) {
    status = json['status'];
    msg = json['msg'];
    data = json['data'] = Data.fromJson(json['data']);
  }
}

class Data {
  String? result;
  Scorecard? scorecard;

  Data({this.result, this.scorecard});

  Data.fromJson(Map<String, dynamic> json) {
    result = json['result'];
    scorecard = json['scorecard'] != null
        ? Scorecard.fromJson(json['scorecard'])
        : null;
  }
}

the quicktype cannot work with digits, I don't know why is this. I think they are in the developing stage. I Have the answer. I'menter image description here looking for the correct answer.



Solution 1:[1]

You can use https://jsontodart.com/, They are just including digit as model(Class) name. But You have to rename the model name like follows,

class 1 {
    String score;
    String wicket;
    String ball;

    1({this.score, this.wicket, this.ball});

    1.fromJson(Map<String, dynamic> json) {
        score = json['score'];
        wicket = json['wicket'];
        ball = json['ball'];
    }

    Map<String, dynamic> toJson() {
        final Map<String, dynamic> data = new Map<String, dynamic>();
        data['score'] = this.score;
        data['wicket'] = this.wicket;
        data['ball'] = this.ball;
        return data;
    }
}

to

class teamA {
    String score;
    String wicket;
    String ball;

    teamA({this.score, this.wicket, this.ball});

    teamA.fromJson(Map<String, dynamic> json) {
        score = json['score'];
        wicket = json['wicket'];
        ball = json['ball'];
    }

    Map<String, dynamic> toJson() {
        final Map<String, dynamic> data = new Map<String, dynamic>();
        data['score'] = this.score;
        data['wicket'] = this.wicket;
        data['ball'] = this.ball;
        return data;
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suresh M