|
Hello Everyone, I'm close to throwing my laptop out the window, I'm new to Swift and have been doing a number of tutorials/examples decoding JSON frile from URL and loading it inot a list. It's all be fine and beautify as the JSON files in the examples are all { key: value } now that I'm trying to do my own project the JSON file I'm dealing with is of this type, whic I'm struggling to decode. Thank you in advance :) JSON Recod from URL
My Data Struct for reading the JSON
My code to fetc/decode JSON and load into List
Errors I'm getting is: swift "typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: \"Expected to decode Array<Any> but found a dictionary instead.\", underlyingError: nil))"" I've tried to change the code to be departure.self in the JSONDecoder but that thows other errors. |
|
There are a number of issues here.
I think that should be all it takes to get you going. If you still find yourself having errors, please post back here and we'll work it out. |
|
And here is a simple example incorporating the changes I mentioned. Obviously, since I don't have everything necessary to fetch your JSON from whatever API it is coming from, I had to improvise, but this should be sufficient to give you an idea how to proceed. Feel free to ask questions.
|
|
Hi @roosterboy Thank you for your time, and a massive thank you for helping me get this to work :) Your code works a treat, I've just changed it to parse the remote URL. Appologies for not sharing the URL, It needs a username/password to access. Again thank you! Hope I can do the same for someone in the community |
|
If you use Ducky (which you can change the Property Naming style) for the model. I have commented out the properties and objects that are empty as do not know what in them.
Paul has done a nice extension that you can use set up a new file called
And then in the
|
|
Hi @NigelGee Thanks for that additional context, also Ducky Model Editor is ace - Cheers again |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
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.