gpt4 book ai didi

ios - 由于从 api 解包值而崩溃(使用 Alamofire)

转载 作者:行者123 更新时间:2023-11-28 12:04:24 26 4
gpt4 key购买 nike

<分区>

我有这个结构来解析来 self 的 api 的值..

struct Deals {
let title: String
let detail: String

init(title : String, detail: String) {
self.title = title
self.detail = detail

}
}

现在我正在以这种格式解析来自 Alamofire 的数据...

     if httpResponse.statusCode == 200 {

if let result = response.result.value as? [String:Any] {
guard let top = orderData["data"] as? [Any] else {
return
}
for value in top {
let aDict = value as? [String : Any]

let title = aDict!["title"] as? String

let detail = aDict!["description"] as? String

let theDeals = Deals(title: title!, detail: detail!)
}
}
}

但是其中一些值在服务器上有一个 nil 值(例如,detail 在服务器上是 nil),所以它会导致崩溃。我无法正确使用 if let 来处理崩溃。希望有人能帮忙...

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