我正在使用自定义可编码类事件。如何将请求中生成的 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 {
}
}
}
}
最佳答案
执行此操作后,将数组数据从模型传递到您创建的数组
let jsonDecoder = JSONDecoder()
let genaricModel = try jsonDecoder.decode(EventModel.self, from: JSON.data(using: .utf8)!)
关于ios - 如何将从该请求收到的数据或 json 附加到空数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56407375/