|
Does anybody have a clue how to decode a JSON file if some of the parameters have hyphens in them
Using examples from moonshot project to create a codable structure like this
I get the error "Consecutive declarations on a line must be separated by ';'" I gues it thinks its a minus sign |
|
From what i have read, hyphens should not be used in javascript notation. Like a lot of programming languages they can only contain certain characters. One of them is Swift and thats why you are getting that error. You cannot declare variable with the character '-'. The json file might be a typo so I would probably just modify the json file property to read uploadTime and go from there. I dare say that most json files you will be getting wont have hyphen in the names so you shouldn't come across it again. Dave |
|
Thank you for the reply. The JSON comes from a web API for Polar (heartrate monitors etc.) as an example response and is full of hyphens. https://www.polar.com/accesslink-api/#get-exercise |
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! |
|
You have to use a Try this in a playground:
|
|
Many thanks for that. I looked at keycodingstatergy but seemed hard. https://developer.apple.com/documentation/foundation/jsondecoder/keydecodingstrategy |
|
Another quick question, hpw do you handle nestd data in the JSON eg.
|
|
|
|
You could also nest the
|
|
|
|
Quinn, I'm still finding my way through some of these concepts, but I noticed that you said CodingKeys seemed hard. Of course; they're not familiar looking things. But I'll call on former teaching experience and encourage you to watch a variety of YouTubes, then Paul's HWS videos again. Take breaks between each view, and give yourself another 5 or 6 exposures; by the fifth view, things will seem more familiar. |
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.