TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

JSON Parsing {"git": [ Having problems in making it work

Forums > Swift

My Xcode file for help

Please look at my JSON on line #55 which I have commented out. My program works with Line # 54. All you need to do is Un-comment line #55 to switch out JSON'S What is fustrating is that I have been on this now for 8 days with not even coming close in to making it work. Thank you ahead of time for helping me out. robert

Line # 54 is identical except that line 55
{"git":[ { "login": "mojombo", "id": 1, } ] }

2      

Your two JSON files are not the same.

The one from line 54 has an array at the root:

[
  {
    "login": "mojombo",
    "id": 1,
    "node_id": "MDQ6VXNlcjE=",

while the one from line 55 has a "git" key:

{"git":[
  {
    "login": "mojombo",
    "id": 1,
    "node_id": "MDQ6VXNlcjE=",

The data struct you pass to JSONDecoder().decode(_:from:) needs to account for that difference.

You can do so this way:

  1. On line 82, change the property name to git instead of stories
  2. On line 105, use StoriesResponse.self instead of [JSONData].self
  3. On line 106, use completion(user.git) instead of completion(users)

3      

NOW I FINALLY GET IT, there was no way for me to finally understand the JSON response that the way you have pointed it to me. UNLESS I SPENT THE STRUGLING WEEK THAT I HAD. Thank you so much. I have finally found out my mistake. I am so appriciative for pointing out my 3 mistakes.

Sincerely robert

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.