David Henry
David Henry

Reputation: 3062

JSON Decoder Swift 4.0

I have a JSON response from an API call.

I'm trying to use the Swift JSON Decoder however, I am getting the following error. [As per attached image] I'm assuming the JSON Decoder only works when you pull the JSON direct from a URL? - Correct me if I'm wrong. Is there a way to use the Swift JSONDecoder() on this API request with this result? Image attached with some JSON in my console.

Error, Request & JSON Result

Upvotes: 0

Views: 308

Answers (1)

rob mayoff
rob mayoff

Reputation: 386078

The error says the decode method wants a Data, but you’re passing it a tuple containing an [Product] and a ProductListMeta?. In other words, you don’t have a JSON response. The JSON has already been decoded for you. Just use productList.products.

Upvotes: 2

Related Questions