title: How do I parse JSON data into a table view?
body: <p>all Im a noob at swift lets just set the record, </p>
  
  <p>Im trying to parse JSON data from an external php file and display the data in a tableview, the data is from a php file hosted elsewhere, its values are</p>
  
  <pre><code>{
      'id' : '1',
      'username' : 'test',
      'password' : 'test',
      'email' : 'test@test.com'
   }
  </code></pre>
  
  <p>My code is as follows</p>
  
  <pre><code>class ForuthTableViewController: UITableViewController {
  
  @IBOutlet var userTable: UITableView!
  @IBOutlet weak var refreshButton: UIBarButtonItem!
  
  
  var values:NSArray = []
  
  override func viewDidLoad() {
      super.viewDidLoad()
      getUsers()
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  @IBAction func refreshPressed(_ sender: UIBarButtonItem) {
      getUsers()
  }
  
  func getUsers(){
  
      let url = NSURL(string: "http://xxx.xxxxxx.xx/get.php")
  
      let userdata = NSData(contentsOf: url! as URL)
  
      do {
          values = try JSONSerialization.jsonObject(with: userdata as! Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
  
          print("Parse success")
      } catch {
          print("Parse error")
          return
      }
      print(values)
  
  
      //userTable.reloadData()
  
  }
  
  override func numberOfSections(in tableView: UITableView) -&gt; Int {
      // #warning Incomplete implementation, return the number of sections
      return values.count
  }
  
  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      // #warning Incomplete implementation, return the number of rows
      return 0
  }
  
  
  
  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
      let cell = tableView.dequeueReusableCellWithIdentifier("userCell", forIndexPath: indexPath) as! UITableViewCell
  
      let maindata = values[indexPath.row]
      cell.username.text = maindata["username"] as? String
      cell.password.text = maindata["password"] as? String
      cell.email.text = maindata["email"] as? String
  
      return cell
  
  }
  }
  </code></pre>
  
  <p>I followed a tutorial on youtube of creating a login / register app but it was from an old version of xcode and when I copy the code across theres errors everywhere so not sure where to start, </p>
  
  <p>Tried looking for a simple JSON tutorial but there are so many different ways to approach JSON I'm not sure which is the right one.</p>
  
  <p>Any ideas would be appreciated, or perhaps a simple fix.</p>