|
Hi all. I have an error as Xcode isn’t letting me parse my JSON file data into an array. It says in the diagnostic report that “Fatal error: Couldn’t parse Rest.json as Array: dataCorrupted(Swift.DecodingError.Context(codingPath: , debugDescription: “The given data was not valid JSON.”, underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 “No string key for value in object around character 3.” UserInfo={NSDebugDescription=No string key for value in object around character 3.}))): file SaiMirrasKitchen/ModelData.swift, line 30” So if anyone could help, I would appreciate it!
JSON file and parsing code in this folder https://drive.google.com/drive/folders/1dyBUFaezJuQMOwndrQYgGdwEGemNQEAj?usp=sharing |
|
hi, my quick guess: if you want to read an array, your .json file should start with the file you have starts with hope this helps, DMG |
|
Thank you, but unfortunatley, this doesn't work. I am getting an error of "
|
|
In the future, please supply a github link or post your code directly in the forums. That makes it so much easier for other people to assist you.
That first But let's say we just add a key
You need a comma after So fix those two issues and then your JSON will validate.
And that works. |
|
hi, yup, @roosterboy found the interior problem of the missing comma for something you might try in the future when parsing json is to add this convenient extension to Bundle, courtesy of Paul Hudson. it will pick up more errors in JSON, although unfortunately in this case, the report will be that "... it appears to be invalid JSON". you would use it as
hope that helps, DMG |
|
@roosterboy @delawaremathguy Thank you for helping me! I have a question, what value do I put right here?
Right inside the RestuarantRows String? |
|
Hi @HSSwift_Harri I found this site very useful when dealing with JSON files https://app.quicktype.io or https://jsoneditoronline.org to see what is missing. Where is your JSON located in the Bundle (in your project) or on the web. If in the Bundle you may want to watch the live steam yesterday when Paul build a app using JSONs Build your first iOS app with SwiftUI If from the web check out Parsing JSON using the Codable protocol with a little change can be used in SwiftUI Nigel PS you put this "Swift" Forum and not "SwiftUI" |
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.