title: Looping through JSON object in Swift
body: <p>I got this JSON object which I sent from my server to my Swift application.</p>
  
  <pre><code>{
    "625289": {
      "id": 1,
      "subject": "Hello World"
    },
    "625277": {
      "id": 2,
      "subject":"Bye World!"
    }
  }
  </code></pre>
  
  <p>So i tried to get the subject for each result ("625289" and "625277") by doing as below in my Swift class: </p>
  
  <pre><code>struct Resultat : Decodable   {
    let subject: String
  }
  
  var result = [Resultat]()
  let urlll = URL(string:"http://localhost:8888/api/pouet.php")
  
  URLSession.shared.dataTask(with: urlll!) { (data, response, error) in
    do {
      print("coucoulol")
      //print(response)
  
      self.result = try JSONDecoder().decode([Resultat].self, from: data!)
  
      print(self.result)
  
      for eachTicket in self.result {
        print(eachTicket.subject)
      }
    } catch {
      print("error"+error.localizedDescription)
    }
  }.resume()
  </code></pre>
  
  <p>However, when I tried to execute the code, it says "The data couldn’t be read because it isn’t in the correct format." From what I understand, the loop for in the code is suffice to get the values in the arrays or maybe I'm wrong. Any help is appreciated, thanks.</p>