I try to decode a JSON of this structure:
The "Time Series (5min)" Object is a dictionary of Objects, but I don't know how to decode this JSON using the Codable Protocol when the keys of the dictionary are changing whenever I load the JSON.
I tried to write some models, but whenever I try to access the dictionary I get nil.
struct stock: Decodable{
let function: Function?
enum CodingKeys: String, CodingKey {
case function = "Time Series (5min)"
}
}
struct Function: Decodable{
let values: [String:Value]
}
struct Value: Decodable{
let open: String
let heigh: String
let low: String
let close: String
let volume: String
enum CodingKeys: String, CodingKey{
case open = "1.open"
case heigh = "2. heigh"
case low = "3. low"
case close = "4.close"
case volume = "5.volume"
}
}
How can I write my code in a way that I don't need to know the keys in advance, but also get them at the end to display the data with the correct date. Thank you