My JSON structure looks like this:
{
"code": 200,
"status": "Ok",
"etag": "7232324423",
"data": {
"offset": 0,
"limit": 25,
"results": [{
"id": 1011244,
"name": "Miss Nesbit",
"description": "",
"modified": "2018-04-04T20:15:35-0400",
"thumbnail": {
"path": "http://i.annihil.us/u/prod/i/mg/8/70/4c002efc322e3",
"extension": "jpg"
}
},
{
"id": 1011244,
"name": "Miss Solis",
"description": "",
"modified": "2018-09-04T20:15:35-0400",
"thumbnail": {
"path": "http://i.annihil.us/u/prod/i/mg/8/70/4c002efc382e3",
"extension": "jpg"
}
}
]
}
}
I want to parse the results in a struct as follows:
struct Character: Codable {
let id: Int
let name: String
let thumbnail: Thumbnail
let description: String
}
However I'm a bit confused about where I specify I only want the results part ? Would I do it when implementing Decodable as follows?
let container = try decoder.container(keyedBy: CodingKeys.self)
let data = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
let results = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .results)
Or do we have to map out each nested section? ANy help or guidance would be so appreciated! :)