Swift 4 decodable with unknown dynamic keys
问题 I have the following JSON {"DynamicKey":6410,"Meta":{"name":"","page":""}} DynamicKey is unknown at compile time.I'm trying to find a reference how to parse this struct using decodable. public struct MyStruct: Decodable { public let unknown: Double public let meta: [String: String] private enum CodingKeys: String, CodingKey { case meta = "Meta" } } Any ideas? 回答1: To decode an arbitrary string, you need a key like this: // Arbitrary key private struct Key: CodingKey, Hashable,