我正在使用自定义可编码类Events。我如何将请求中的结果json附加到一个空数组以填充表?
var events = [Events]()
let URL_GET_DATA = "http://192.168.100.4/PrototypeWebService/api/getevents.php"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Alamofire.request(URL_GET_DATA).responseJSON{ response in
if let json = response.result.value {
print(json)
do {
let decoder = JSONDecoder()
self.EventTable.reloadData()
} catch {
}
}
}
}
答案 0 :(得分:0)
pass your array data from your model to the array you created, after doing this
let jsonDecoder = JSONDecoder()
let genaricModel = try jsonDecoder.decode(EventModel.self, from: JSON.data(using: .utf8)!)