I am getting JSON response like this
"dict": [
"key1" : "val1",
"key2" : "val2",
...
]
Server always returns this dict in ordered manner key1, key2, ... Is it possible to parse this dict in ordered manner.
I can use
try container.decode([String: String].self, forKey: .dict)
But this is unordered parsing
I try also getting nested container like
try container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .dict)
struct DynamicCodingKey: CodingKey {
var stringValue: String
var intValue: Int?
init?(intValue: Int) {
self.intValue = intValue
self.stringValue = "\(intValue)"
}
init?(stringValue: String) {
self.stringValue = stringValue
self.intValue = Int(stringValue)
}
}
But KeyedDecodingContainer<DynamicCodingKey> also seems to store unordered keys when I get them using .allKeys like standard HashTable.