Hi I have the following structure nested in a bigger structure that is returned from an api call but I can\'t manage to encode/decode this part. The problem I am having is t
Simplified answer, it is working with dictionary [String: String] (instatead of String you can use other struct):
let jsonData = """
{
"current": "a value",
"hash": "a value",
"values": {
"key1": "customValue",
"key2": "customValue"
}
}
""".data(using: .utf8)!
struct MyModel: Decodable {
var current: String
var hash: String
var values: [String: String]
}
let model = try JSONDecoder().decode(MyModel.self, from: jsonData)
for (key,value) in model.values {
print("key: \(key) value: \(value)")
}