I\'m trying to implement the new Codable
protocol, so I added Codable
to my struct, but am stuck on decoding the JSON.
Here\'s
You're getting this error because your JSON is likely structured as so:
{
"themes": [
{ "title": ..., "question": ..., "answer": ... },
{ "title": ..., "question": ..., "answer": ... },
{ ... }
],
...
}
However, the code you wrote expects a [Question]
at the top level. What you need is a different top-level type that has a themes
property which is a [Question]
. When you decode that top-level type, your [Question]
will be decoded for the themes
key.