Fatal Error in ModelData at line 43

Failed to decode landmarksData.json from bundle because it appears to be invalid JSON.

Full disclosure - Im extremely new to this and am playing around with the swift tutorials to see what it can do and see if I could build an app.

Any advice is appreciated.

I added a few locations to the SwiftUI Tutorial for Lanmarks and this is what happened. I have checked that JSON file and all commas are in the correct place everything is correct but im getting this error. Not sure what im doing incorrectly.

Can anyone give me assistance on how to fix this. I can only preview favorite button, circle image and map. Everything else appears as Fatal Error in ModelData.

  • Is there anyway to add in the code to narrow why the JSON file is invalid? Like pin pointing the issue?

Add a Comment

Replies

Errors thrown by the JSONDecoder contain detailed information about the line number and column number and an explanation of what failed. If you set a breakpoint at line 29, then in the debugger show the value of error.description or String(describing: error), you should see this additional information. (IIRC it's actually carried in the NSError's userInfo dictionary. Also IIRC, error.localizedDescription does not display this additional information by default.)

  • Thank you! i got a bunch of stuff when entered those into the debugger. Do you know where i would find the information? Im not familiar with how to read and diagnose issues yet with Xcode. Im exteremly new.

Add a Comment

I'm getting back into coding after years away. I ran into the same problem with the tutorial. I also spent a lot of time trying to debug javascript without a debugger, which you do with a lot of console() calls. Fortunately, Swift has print(). So I added a print(error) right after the catch after the decode() in ModelData, and the error was simply that I misspelled "latitude".

Check you Landmark.swift file There may be wrong names of properties or Classes.