📜  如何在飞镖代码示例中迭代对象

📅  最后修改于: 2022-03-11 14:48:05.151000             🧑  作者: 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) { });