|
Hello everyone, I've been following along the bit of code Paul published in this post (https://www.hackingwithswift.com/books/ios-swiftui/sending-and-receiving-codable-data-with-urlsession-and-swiftui) on December 2019, and when I change the JSON URL I got this: Now: 1) of course I have a struct with the exact same variables you find in the JSON (not all of them, but neither had Paul in his example) 2) you don't even get to bother the codebale struct, you fail to fetch not when parsing. Here:
3) I read everywhere this is just a "console noise" but not for me... because JSON isn't either fechted or parsed, the app freezes. 4) very same code but the iTunes url that Paul used as an example and everything works great; I started wondring whether is the JSON itself... but of course I cannot change somebody else's API... 5) I am not enrolled in Apple Dev program, could be that? I seriously doubt it, but I'm giving you every thing I have on my own plate I tried many JSONs: Wordpress's REST service, mock.io and so on. In fact I suggest you to run the code with this super simple JSON (https://jsonplaceholder.typicode.com/todos) Here's what I've done, you can see this is pretty much Paul's code, I didn't even delete his comments:
|
|
Your structs are not correct for the JSON returned by https://jsonplaceholder.typicode.com/todos. You are trying to decode into a In other words, you are trying to decode JSON that looks like this:
but you are actually receiving JSON that looks like this:
So instead of this:
you should have this:
|
|
|
|
Don't feel stupid, I tripped over that EXACT scenario and it took for FOREVER to come to that same realization. This is how we learn. 👊🏼 |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.