我是SwiftyJSON的新手,也是建立新应用的火腿 但是,当我尝试从JSON解析数据时,它只出现在控制台中并且只出现在函数中?
我的代码有什么问题吗?
func CallNames(URl_read : NSMutableURLRequest) {
let Task = URLSession.shared.dataTask(with: URl_read as URLRequest, completionHandler: { (data,response,error) in
if error != nil {
print(error)
}
let readJson = JSON(data: data!, options: JSONSerialization.ReadingOptions.mutableContainers, error: nil)
// let arrayNames = readJson["Result"].arrayValue.map({$0["Names"].stringValue})
if let stations = readJson["Result"].array {
for d in stations {
let NamesInside = d.dictionaryValue["Names"]
if NamesInside != nil {
self.NamesResturant_.append((NamesInside?.string!)!)
}
}
}
self.tableView.reloadData()
})
Task.resume()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Names", for: indexPath) as! Rest_Cell
// Configure the cell...
if NamesResturant_.count != 0 {
cell.RestName.text = NamesResturant_[indexPath.row]
}
return cell
}
答案 0 :(得分:0)
代码工作正常,但我忘记将表的部分更改为1而不是0