对成员 'decode(_:forKey:)' swift4 的不明确引用

Ambiguous reference to member 'decode(_:forKey:)' swift4

我正在解析需要从服务器上的字典(这是一种遗留数据格式)转换为客户端简单的字符串数组的响应。因此,我想将名为 'data' 的密钥解码为字典,这样我就可以遍历这些密钥并在客户端创建一个字符串数组。

init(from decoder: Decoder) throws  {
  let values = try decoder.container(keyedBy: CodingKeys.self)
  do {
    let some_data_dictionary = try values.decode([String:Any].self, forKey: CodingKeys.data)

    for (kind, values) in some_data_dictionary {
      self.data_array.append(kind)  
    }
  } catch {
    print("we could not get 'data' as [String:Any] in legacy data \(error.localizedDescription)")
  }
}

我得到的错误是:Ambiguous reference to member 'decode(_:forKey:)'

看起来 Swift 'Codable' 不能支持 Any 或使用 [String:Any],所以在这里使用这个 post

我能够为 class 我不会使用的名为 LegacyData 的结构,然后将键解压到一个字符串数组中

    do
    {
      let legacy_data = try values.decode([String:LegacyData].self, forKey: CodingKeys.data)

      self.array = Array(legacy_data.keys)
    }
    catch
    {
      print("no legacy_data \(error) \n")
    }