【问题标题】:Ignore a Key with JSON encode使用 JSON 编码忽略密钥
【发布时间】:2020-02-01 05:03:44
【问题描述】:

使用json.encode时如何忽略键?

类似这样的:

final map = json.decode(json.encode(routine), reviver: (key, value) {
      if (key == "id") {
        return null;
      }
      return value;
    });

但是这样我的地图有一个键id,值为null。我希望我的地图没有 id 键。

有什么想法吗?

【问题讨论】:

    标签: flutter dart jsonserializer


    【解决方案1】:

    您可以删除密钥。

    routine.remove("id");
    final map = json.decode(json.encode(routine));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      相关资源
      最近更新 更多