title: JSON decode from url in SWIFT
body: <p>I am trying to decode the following JSON from an URL:</p>
  
  <pre><code>{
  "date":"2018-08-17",
  "data":[
         {"id":"IDD","rate":"1.1","name":"My test ID"},
         {"id":"IDX","rate":"101.12","name":"Another test ID"}
         ]
  }
  </code></pre>
  
  <p>My swift file looks like:</p>
  
  <pre><code>struct Container: Codable {
  let date: String
  let data: [MyData]
  }
  
  struct MyData: Codable {
  let id: String
  let rate: Double
  let name: String
  }
  
  // This outputs the required json string    
  if let url = URL(string: "https://www.xxx.php") {
  
  do {
      let contents = try Data(contentsOf: url)
  
      do {
          let decoder = JSONDecoder()
          let jData: Container = try decoder.decode(Container.self, from: contents)
  
          print("The data presented is from \(jData.date)")
  
          for id in jData.data {
              // Here I want to get an array of the json data
              print(id.id)
          }
  
      } catch {
          print(error.localizedDescription)
      }
  
  } catch {
      print(error.localizedDescription)
  }
  
  }
  </code></pre>
  
  <p>My code throws the error: The data couldn’t be read because it isn’t in the correct format.</p>
  
  <p>What am I doing wrong? Do you maybe also have a suggestion on how to improve my code in general?</p>
  
  <p>Thanks for your help!</p>