|
Hello, I have a second API question, apologies for that but I'm finding this decode thing tricky to understand, especially for large JSON files. So I have a large JSON link below. https://1drv.ms/t/s!Ahk-sk_KQft1jKkzdBku2jsfUQ3O9w Out of this JSON I really only want to interrogate the fields Id, Name, Type and Kind. Below is an extract from the link above. (this starts at line 2049 of the linked JSON)
I've tried a number of decode structs, the last two are below. Everything compiles OK but I get 'nil' returned for all fields wuth both of these. STRUCT1
STRUCT2
If anyone can advise before I pull out all of my hair i'd really appriciate it. |
|
Hi, My recomendation is to paste your json in to a website like Quicktype and use their structs, i got it to work with one i got from the site, just remove whatever you dont need. |
|
I have been (as Paul says) noodling about and com up with this I add the JSON file to the
Then View
PS added an
|
|
Thank you very much @Hectorcrdna and @NigelGee. Both super helpful responses. I think I need to do better understaing the structure of JSON. My challenge here is that it's tricky to see the structure of complex json vis-a-vis the various arrays within arrays, then build a STRUCT to get at the data. QuickType is great but it gives me everything, then I need to understand how to trim the output to just focus on the fields i'm interested in. So @NigelGees response was great because it showed me exactly how the STRUCT should be trimmed. It would be really handy if a tool like Ducky (or QuickType) would asked the user what fields they want to include in the STRUCT and trim accordingly. :) Thanks again fellas! |
|
Then look at the keys you want and put a comment (
If if works and builds then you can delete the comment keys and end up with the simple PS You can (in Ducky) to ignore properties by adding the "path" eg |
|
SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.