1
我有一个问题。我正在用alamofire回报它的回报价值。在alamofire我将返回的json转换为我的自定义类,它的工作goog。但是当我将这个转换后的类从alamofire body中取出时,它返回了零值。 我在alamofire中放置了断点,在那里我转换了json的值,并且向我的类中添加了它,它具有价值,并将它放到我的类中。但是超出正文它等于零。为什么?alamofire得到请求返回空值
func getZakazDetail(orderID:Int,tableView:UITableView,spinner:UIActivityIndicatorView){
if flag{
let zD=ZakazDetailTableViewController()
Alamofire.request(.GET, "myUrl")
.responseJSON { response in
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling GET on /todos/1")
print(response.result.error!)
return
}
if let value = response.result.value {
let product = JSON(value)
if product != nil{
for (_,subJson):(String, JSON) in product {
let p=ZakazDetail(id: subJson["id"].int!, tovar: subJson["tovar"].string!, count: subJson["count"].int!, orderid: subJson["orderid"].int!, cena: subJson["cena"].int!)
self.zakazDetail.append(p)
zD.detail.append(p)
}
}
}
}
spinner.stopAnimating()
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
tableView.reloadData()
}
else{
let alert = UIAlertView(title: "Ошибка",message: "Нету интернета!",delegate: nil,cancelButtonTitle: "OK")
alert.show()
}
}
但也有它已经下载JSON让产品= JSON(值) –
呀很好,你应该告诉代码在alamofire加载数据之前不会追加任何内容,然后一旦完成,您可以追加它并重新加载数据。 – Dershowitz123
是这样的: func getZakazDetail(orderID:Int,tableView:UITableView,spinner:UIActivityIndicatorView,completion:(JSON) - >())let product = JSON(value) 完成(产品) –