如何使用键路径从嵌套的字典dart中获取值。

问题描述 投票:0回答:1

我想知道如何获得嵌套字典的值或使用dart(Flutter)中的keypath来更新嵌套字典的值。

flutter dart
1个回答
0
投票

如果你有一个这样的字典。

{
    "example": {
        "a": "valA",
        "b": "valB",
        "c": "valC",
    }
}

你可以创建一个类来解析这个对象。

class Example {
  String a;
  String b;
  String c;

  Example({
    this.a,
    this.b,
    this.c,
  });

  factory Example.parseJSON(Map<String, String> json) {
    return Example(
      a: json['example']['a'],
      b: json['example']['b'],
      c: json['example']['c'],
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.