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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

using productList.products is returning the same "Cannot convert value of type '[Product]' to expected argument type 'Data"
Use productList.products instead of trying to decode anything. All the decoding was already done for you because you are using the Moltin Swift library. You are not talking JSON directly.
I see. Sorry this might sound very amateur but how do I then assign productList.products to my data model?
Whatever you were planning to do with the array returned by decode(_:from:), you should do with productList.products instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.