使用swift 4和Alamofire在UITableView中显示JSON数据

使用swift 4和Alamofire在UITableView中显示JSON数据,json,swift,alamofire,swift4,Json,Swift,Alamofire,Swift4,我是斯威夫特的新手,我需要你的帮助。我正在用swift解析JSON数据,如下所示: 这是我写的代码 import UIKit import Alamofire import SwiftyJSON class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{ @IBOutlet weak var tableView: UITableView! var albumArray = [A

我是斯威夫特的新手,我需要你的帮助。我正在用swift解析JSON数据,如下所示: 这是我写的代码

import UIKit
import Alamofire
import SwiftyJSON

class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{

    @IBOutlet weak var tableView: UITableView!

var albumArray = [AnyObject]()
    var url = ("https://jsonplaceholder.typicode.com/photos")

        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.

                  Alamofire.request("https://jsonplaceholder.typicode.com/photos").responseJSON { (responseData) -> Void in
                if((responseData.result.value) != nil) {
                    let swiftyJsonVar = JSON(responseData.result.value!)
//
                    if let resData = swiftyJsonVar[].arrayObject {
                        self.albumArray = resData as [AnyObject]; ()

                    }
                    if self.albumArray.count > 0 {
                        self.tableView.reloadData()
                    }
                }
            }

        }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return albumArray.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? CostumTableViewCell

        let title = albumArray[indexPath.row]
        cell?.titleLabel?.text = title["title"] as? String

        return cell!
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

问题是没有任何错误,但不显示数据。您还可以看到JSON:

您的代码对我也适用。在主队列中重新加载,并确保为单元格中的标签设置约束。连接tableview的数据源和委托,然后进行检查。

能否更准确地解释问题中的“不起作用”部分?@KeyurTailor不显示数据。很抱歉,您是否尝试在console中打印数据?@KeyurTailor是的,console中的数据已成功打印。因此,我建议您检查正在接收的数据的格式。