答案 0 :(得分:1)
只需执行所有步骤。
步骤1-像这样创建模型
class Teachers: Codable {
var id: Int?
var name: String?
var position: String?
var subj: Int?
var depart: Int?
var lect: Int?
var pract: Int?
}
第2步:这样映射
do {
// Decode data to object
let url = Bundle.main.url(forResource: "JSON_DATA_TEACHERS", withExtension: "json")
let jsonData = try Data(contentsOf: url)
self.teachers = try JSONDecoder().decode([Teachers].self, from: jsonData)
self.tableView.reloadData()
}catch {
print("Json Mapping Error: " + error.localizedDescription)
}