|
Hi everyone, I posted a question yesterday concerning my challenges creating a Struct to get data out of a JSON. I addressed the Any? issue thank to the help from @ygeras. But i'm still stuck. I want simply to select the following data frol the JSON:
My Struct looks like this
And I decode like this
But I get the error:
Think is the JSON is complex (at least for me) and so i'm not understanding how to construct a working Struct. Rather than past the JSON here, here is a link because is quite long. https://1drv.ms/u/s!Ahk-sk_KQft1jIVx2MBugOCmZy74lA If anyone can gve me any pointers , that would be amazing. Thank you! |
|
|
|
Not sure if those are exactly the items you are trying to extract. But to me the hierarchy seems as follows:
|
|
There is alot of field. The
Find the field(s) that you want eg
Then trace the
|
|
@Hectorcrdna, apologies I can't because i'd have to give you a token too and i'm not allowed to share that. @NigelGee, thank you for that. I feeling dumb because i'm not sure how to implement your suggestion. I understand what a Dictionary is generally speaking but in this example with a dictionary/struct i'm lost at the moment. I changed the struct to
and then used
and I get
I guess I don't understand how implement your suggestions. Apologies for my lack of knowledge on this one. I'm gonna have to search youtube to learn more about this Struct thing. |
|
Without the URL to test but what i have do is copied the JSON you into the bundle and tried from there
I have Data So it will be with the call for the data not the |
|
@NigelGee Thank you! Thank you! Putting it all in context is much clearer! So happy. I'll spend some quality time this weekend learning more about Structs and APIs :) And BTW I also learned about Bundles, so thanks for that. It's really useful because I'll be spending 36 hours on aircraft over the next 2 weeks without wifi so i'll be able to experiment and test offline :) |
|
Curly braces {} hold objects. The data are in key, value pairs. Square brackets [] hold arrays. Each data element is enclosed with quotes if it's a character, or without quotes if it is a numeric value. Commas are used to separate pieces of data. |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
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.