【发布时间】:2016-06-30 11:25:32
【问题描述】:
我正在使用 Alamofire 进行 JSON 解析。我可以从网络服务获取数据。我想设置标签。我可以使用“print()”函数打印任何数据。但我不能设置标签。请帮帮我。
我的代码在这里。
Alamofire.request(.GET, "url").validate().responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let jsonObject = JSON(value)
// this row is working.
print(jsonObject["Title"].stringValue)
// i can not print to label here
if let titleValue = jsonObject["Title"].string {
self.newsTitleLabel.text = titleValue
}
}
case .Failure(let error):
print(error)
}
}
//print result:
Bolu Dağı'nda bayram tatili yoğunluğu
//if blok:
fatal error: unexpectedly found nil while unwrapping an Optional value
【问题讨论】:
-
你遇到了什么错误?
-
直接试试
self.newsTitleLabel.text = jsonObject["Title"].stringValue看看是否有效。 -
问题已更新。
-
@Santosh 不幸的是它不起作用
-
你的意思是崩溃在线
self.newsTitleLabel.text = titleValue,对吧?如果是这样,newsTitleLabel是否存在?它是什么 - IBOutlet/var?请输入该代码以及您调用此服务的位置。
标签: json swift parsing alamofire