My scenario, I am trying to load JSON
data into UITableView
. Here, the problem is my JSON having multiple array
of multiple values
. I need to get array keys
as a Tableview section
names and its all values
load into relevant cell
. I am using codable
method for easy JSON data process. Now, how to do array key names (School, Office, etc,) into section and its values relevant cell.
My JSON
https://api.myjson.com/bins/r763z
My Codable
struct Root : Decodable {
let status : Bool
let data: ResultData
}
struct ResultData : Decodable {
let school, college, office, organisation, central : [Result]
}
struct Result : Decodable {
let id, name, date : String
let group : [String]
}
My JSON Decoder Code
func loadJSON(){
let urlPath = "https://api.myjson.com/bins/r763z"
let url = NSURL(string: urlPath)
let session = URLSession.shared
let task = session.dataTask(with: url! as URL) { data, response, error in
guard data != nil && error == nil else {
print(error!.localizedDescription)
return
}
do {
let decoder = JSONDecoder()
self.tableData = try decoder.decode(DivisionData.self, from: data!) // How to get section values and cell values and load table data
DispatchQueue.main.async {
self.tableView.reloadData()
}
} catch { print(error) }
}
task.resume()
}