Swift Alamofire JSON解析

时间:2016-06-30 11:25:32

标签: json swift parsing alamofire

我正在使用Alamofire进行JSON解析。我可以从Web服务获取数据。我想设置标签。我可以使用" 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

1 个答案:

答案 0 :(得分:0)

你的意思是崩溃在self.newsTitleLabel.text = titleValue线上,对吧? 确保您的newsTitleLabel确实存在IBOutlet / variable。