【问题标题】:Swift Alamofire JSON ParsingSwift Alamofire JSON 解析
【发布时间】: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


【解决方案1】:

你的意思是崩溃在线self.newsTitleLabel.text = titleValue,对吧? 确保您的 newsTitleLabel 确实存在,或者它是 IBOutlet/变量。

【讨论】:

    猜你喜欢
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    相关资源
    最近更新 更多