I've a JSON like this.
I need to make a corresponding Decodable struct in my iOS app using Swift 4.
{
"cherry": {
"filling": "cherries and love",
"goodWithIceCream": true,
"madeBy": "my grandmother"
},
"odd": {
"filling": "rocks, I think?",
"goodWithIceCream": false,
"madeBy": "a child, maybe?"
},
"super-chocolate": {
"flavor": "german chocolate with chocolate shavings",
"forABirthday": false,
"madeBy": "the charming bakery up the street"
}
}
Need help on making the Decodable Struct. How to mention the unknown keys like cherry
,odd
and super-chocolate
.
What you need is to get creative in defining the
CodingKeys
. Let's call the response aFoodList
and the inner structureFoodDetail
. You haven't defined the properties ofFoodDetail
so I assume that the keys are all optional.