📜  通过对象的 dart 循环 - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:07.838000             🧑  作者: Mango

代码示例2
// You have several options, the simple way for me is 
  // create method "toJson" inside of the class,
  // and then iterate over the return of method "toJson". 
  
example :

class MyModel() {
  int value1;
  String value2;
  bool value3;
  
  MyModel({
    this.key1,
    this.key2,
    this.key3});
  
  Map  toJson() {
    return {"key1": value1, 
        "key2":value2,
        "key3":value3 };}
  }

  MyModel.toJson().forEach((key, value) { });