gpt4 book ai didi

json - 从 JSON API 下载 Alamofire

转载 作者:可可西里 更新时间:2023-11-01 02:06:44 25 4
gpt4 key购买 nike

我试图通过 api 在标签上设置文本,但似乎甚至没有调用该函数。请引用下面的片段。有什么问题吗?

编辑:typealias DownloadComplete = () -> ()

var date: String = ""

override func viewDidLoad() {
super.viewDidLoad()

timeLbl.text = date

// Do any additional setup after loading the view.
}

func downloadTimeData(completed: @escaping DownloadComplete) {
//Downloading forecast weather data for TableView
Alamofire.request(APIURL).responseJSON { response in

let result = response.result

if let dict = result.value as? Dictionary<String, AnyObject> {
if let currentDate = dict["fulldate"] as? String {
self.date = currentDate
print(self.date)
print("xxx")
}
}
completed()
}
}

最佳答案

我通过 alamofire 文档找到了更简单、更容易的方法。

override func viewDidLoad() {
super.viewDidLoad()

Alamofire.request(APIURL).responseJSON { response in
print(response.result) // result of response serialization
let result = response.result

if let dict = result.value as? Dictionary<String, AnyObject> {
let currentDate = dict["fulldate"] as? String
self.timeLbl.text = currentDate
}

}
}

关于json - 从 JSON API 下载 Alamofire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42352553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com