如何使用swiftyJson从json解开int响应?我在func fecthData()中获取fetchData collectionView时总是会出错。
这是我的代码:
class ViewController: ViewController,UITableViewDataSource, UITableViewDelegate {
var data = [modelKuota]()
override func viewDidLoad() {
super.viewDidLoad()
fetchData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "QuotaCollectionViewCell", for: indexPath) as! QuotaCollectionViewCell
cell.textLable.text = data[indexpath.row].quota
cell.textLable1.text = data[indexpath.row].date
return cell
}
func fetchData(){
Alamofire.request(url, method: .post, parameters: parameter, encoding: URLEncoding.default).responseJSON { (response) in
switch response.result{
case .success(let value):
print(value)
let json = JSON(value)
let quota = json["data"]["quota"].stringValue
let quota1 = json["data"]["quota1"].stringValue
let date = json["data"]["date"].stringValue
let date1 = json["data"]["date1"].stringValue
let totalQuota = modelKuota.init(quota: quota , date: date)
let totalQuota1 = modelKuota.init(quota: quota1 , date: date1)
self.data.append(totalQuota)
self.data.append(totalQuota1)
self.collectionView.reloadData()
case .failure(let error):
print(error)
}
}
}
}
我收到错误collectionView.reloadData()
线程1:致命错误:在展开可选值时意外发现nil