ios - 如何将从该请求收到的数据或 json 附加到空数组?

标签 ios swift alamofire

我正在使用自定义可编码类事件。如何将请求中生成的 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/

相关文章:

ios - 如何在 UIAlertController 中为 UITextField 添加边距?

macos - 无法使用 '==' 类型的参数列表调用 '(UInt16, UInt16)' 吗?

swift - 使用 Alamofire 的同步请求

ios - 如何使用 Alamofire.request() 将 XML soap 响应保存到文件?

android - 连续登录 Android 和 iOS 移动应用程序的策略

ios - Xcode/iOS xctest - 无法找到构建输入文件

ios - 在 iOS Core Audio 中——查找 OSStatus 错误的最佳方式是什么(即 -43?)

ios - 使用 Xamarin 捕获 iOS UITextField 清除事件

ios - 以编程方式在 UIToolbar 中显示或隐藏 UIBarButtonItem

ios - 如何在 Swift 中使用 switch case 描述来自 Alamofire 的错误?