繁体   English   中英

Swift Alamofire JSON解析

[英]Swift Alamofire JSON Parsing

我正在使用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

您是说崩溃发生在self.newsTitleLabel.text = titleValue线上,对吗? 确保您的newsTitleLabel确实存在,或者是IBOutlet /变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM