I am trying to get json from a githubusercontent (URL: https://raw.githubusercontent.com/nacrt/SkyblockClient-REPO/main/files/mods.json) into a Swift file then converting it into something that I can manipulate, for example, using enabled (below) to have a checkbox checked/unchecked.
The JSON in question is actually an array of JSONs, and this is the main problem. I'm not sure if the code below will work, because I haven't imported the JSON.
So far, I've found this:
struct ModsJSON: Decodable {
let id: String
let display: String
let description: String
let url: String
let config: Bool?
let enabled: Bool
let hidden: Bool
let icon: String
let categories: Array<String>
let actions: Array<OptionAction>?
let warning: ActionWarning?
}
let jsonData = JSON.data(using: .utf8)! //JSON being the imported json
let mods_json: [ModsJSON] = try! JSONDecoder().decode([ModsJSON].self, from: jsonData)
I am a beginner in swift, and I realize that this should be easy, but I can't find a practical answer anywhere.
macOS Big Sur - Latest Swift and Xcode versions.