I have the current JSON
"updateTime": "2021-02-12T16:41:21.413Z",
"dueDate": {
"year": 2021,
"month": 2,
"day": 17
},
"dueTime": {
"hours": 4,
"minutes": 59
},
...
How can I retrieve the values of dueDate and dueTime (including all of the data in the dictionary) using Swift?
Thanks in advance
3
Answers
What you posted is not quite a valid JSON, but if it was like this:
then you could convert to
Data
And then parse using
JSONSerialization
:And then each object inside it, becomes another JSON. For example:
If you have json like:
And you decoded it and want to convert to dict and send to server. You can easily write extension to
Encodable
as like:And use it:
My suggestion is to decode the JSON with
Decodable
into structs and join the date and time parts to aDateComponents
instance