作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我有这个结构来解析来 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
来处理崩溃。希望有人能帮忙...
我是一名优秀的程序员,十分优秀!