Swift 3 Load JSON in Tableview : <p>I'm currently working on an app and I would like to display the data I got from a JSON webpage in a TableView... My code to save the JSON-data in an array already works as I can print them every time in the console but the data doesn't load in the tableview and I tried almost everything: changing the cell identifier, using custom cells, etc... Anyone ideas on how to solve this problem?</p>

<pre><code>import UIKit

class TableViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    var names: [String] = []
    var rating: [String] = []

    override func viewDidLoad() {
        super.viewDidLoad()

        let url=URL(string:"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=51.0460761,3.7286716&amp;radius=300&amp;type=bar&amp;key=AIzaSyCpHkY1s-qZjTOyTvDjMgD6hr5VTtEOgpU")

        do {

            let allContactsData = try Data(contentsOf: url!)
            let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
            if let arrJSON = allContacts["results"] {
                for index in 0...arrJSON.count-1 {

                    let aObject = arrJSON[index] as! [String : AnyObject]

                    names.append(aObject["name"] as! String)
                    rating.append(aObject["id"] as! String)
                }
            }

            print(names)
            print(rating)

            self.tableView.reloadData()
        }
        catch {

        }
    }


    func tableView(_ tableView: UITableView!, numberOfRowsInSection section: Int) -&gt; Int {
        return names.count;
    }
    func tableView(_ tableView: UITableView!, didSelectRowAtIndexPath indexPath: IndexPath!) {
        print("You selected name : "+names[indexPath.row])
    }

    func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -&gt; UITableViewCell{
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")

        if !(cell != nil) {
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
        }
        cell?.textLabel?.text=self.names[indexPath.row]
        cell?.detailTextLabel?.text = self.rating[indexPath.row]
        return cell!
    }

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

    override func viewWillAppear(_ animated: Bool) {
        // Hide the navigation bar on the this view controller
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }

    override func viewWillDisappear(_ animated: Bool) {
        // Show the navigation bar on other view controllers
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }


}
</code></pre>

<p><a href="https://i.stack.imgur.com/qQ4X2.png" rel="nofollow noreferrer">As you can see he gives me the 2 lists...</a></p>
