Question:
I need you help to implement a custom JSON decoding. The JSON returned by the API is:Decodable
protocol (by using init(from decoder:)
) to follow this logic? Thank you.Answer:
This is a solution with nested containers. With the given (simplified but valid) JSON stringzones
as nestedUnkeyedContainer
then iterate the array and decode first the name
key and depending on name
the elements.Side note: This way requires to declare the element arrays as
var
iables.If you have better answer, please add a comment about this, thank you!