flutter json to jsonList

数据格式
model类

class GetTodayTask {
  String? checkAt;
  int? number;
  /// 需要巡查数量
  int? tackNum;
  /// 已经巡查数量
  int? checkNum;
  bool? isChoose = false;

  GetTodayTask({
    this.checkAt,
    this.number,
    this.tackNum,
    this.checkNum,
    this.isChoose,
  });

  Map toJson() {
    return Map()
      ..put('checkAt', this.checkAt)
      ..put('number', this.number)
      ..put('tackNum', this.tackNum)
      ..put('checkNum', this.checkNum);
  }

  GetTodayTask.fromJson(Map json) {
    this.checkAt = json.asString('checkAt');
    this.number = json.asInt('number');
    this.tackNum = json.asInt('tackNum');
    this.checkNum = json.asInt('checkNum');
  }
}

网络请求返回的数据格式

 [
        {
            "checkAt": "2021-12-06",
            "number": 2,
            "tackNum": 1,
            "checkNum": 0
        }
    ]

list接收方式

 List list= (data as List)
            .map((e) => GetTodayTask.fromJson(e as Map)).toList();

你可能感兴趣的:(flutter json to jsonList)