I have just been introduced to using JSON data in my iOS app. I used a service to parse JSON data from a website, and I would like to decode that data to display to my user in a UITableView. My JSON data looks as follows:
{
"success": true,
"outputScenario": "Default",
"data": {
"collection": [
{
"teamName": "Gulf Coast Monarchs, FL",
"teamW": "10",
"teamL": "0",
"teamT": "0",
"teamPct": "1.000",
"teamGB": "-",
"teamGP": "10",
"teamRA": "10",
"teamDivision": "10-0-0"
},
{
"teamName": "Ohio Nationals, OH",
"teamW": "9",
"teamL": "1",
"teamT": "0",
"teamPct": ".900",
"teamGB": "1.0",
"teamGP": "10",
"teamRA": "20",
"teamDivision": "9-1-0"
}, {
"teamName": "Mount Kisco Chiefs, NY",
"teamW": "0",
"teamL": "8",
"teamT": "0",
"teamPct": ".000",
"teamGB": "8.0",
"teamGP": "8",
"teamRA": "108",
"teamDivision": "0-8-0"
}
{
"teamName": "Mount Kisco Chiefs, NY",
"teamW": "0",
"teamL": "8",
"teamT": "0",
"teamPct": ".000",
"teamGB": "8.0",
"teamGP": "8",
"teamRA": "108",
"teamDivision": "0-8-0"
}
]
},
Just keep in mind that I have cut out a significant amount of the data provided in the JSON so it is easily viewable.
I would like to decode this data using SwiftyJSON if possible so I can display it to my user in a UITableView. For now, the UITableView will display the team name in the UITableView.textLabel.text and the teamW and teamL in the UITableView.detailTextLabel.text. How would I decode this data using SwiftyJSON? I am struggling to figure out how this type of structure would be decoded. I would like to use the model that I have created:
struct Standing: Decodable {
var teamName: String
var teamW: Int
var teamL: Int
var teamT: Int
var teamPct: Int
teamGB: Int
teamGP: Int
teamRA: Int
teamDivision: String
}