Suppose I have an API that returns this json:
{
"dogs": [{"name": "Bella"}, {"name": "Lucy"}],
"cats": [{"name": "Oscar"}, {"name": "Coco"}]
}
And a model that looks like this:
import Foundation
public struct Animal: Codable {
let name: String?
}
Now I want to decode the array of Animal from the "dogs" key:
let animals = try JSONDecoder().decode([Animal].self, from: response.data!)
However, I somehow have to reference the "dogs" key. How do I do this?