title: Nested JSON to HTML table
body: <p>There might be an idiotic mistake in my code, but I just haven't found the answer yet. I'm using JSON data from <a href="http://rata.digitraffic.fi/api/v1/live-trains/[trainnumber]" rel="nofollow">http://rata.digitraffic.fi/api/v1/live-trains/[trainnumber]</a> which is an external site.</p>
  
  <p>My objective is to get data from array inside JSON array to a simple HTML table, in this case stationShortCode, type, commercialTrack and scheduledTime from all  timeTableRows -arrays. JSON data looks like this:</p>
  
  <pre><code>    [{"trainNumber":9707,
    "departureDate":"2015-06-03",
    "operatorUICCode":10,
    "operatorShortCode":"vr",
    "trainType":"HL",
    "trainCategory":"Commuter",
    "commuterLineID":"H",
    "runningCurrently":false,
    "cancelled":false,
    "version":4295000475,
    "timeTableRows":[  
        {  
          "stationShortCode":"HKI",
          "stationUICCode":1,
          "countryCode":"FI",
          "type":"DEPARTURE",
          "trainStopping":true,
          "commercialStop":true,
          "commercialTrack":"6",
          "cancelled":false,
          "scheduledTime":"2015-06-03T14:48:00.000Z"
       },
       {  
          "stationShortCode":"PSL",
          "stationUICCode":10,
          "countryCode":"FI",
          "type":"ARRIVAL",
          "trainStopping":true,
          "commercialStop":true,
          "commercialTrack":"3",
          "cancelled":false,
          "scheduledTime":"2015-06-03T14:52:30.000Z"
       }, and 5 to 50 timeTableRows more.
  </code></pre>
  
  <p>json.php, which gets the train number from $_GET, looks like this</p>
  
  <pre><code>    &lt;?php
  $juna = $_GET["juna"];?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;&lt;?php
  $juna = $_GET["juna"];
  echo $juna;?&gt;&lt;/h1&gt;
  &lt;script&gt;
  $.ajax({
  url: 'http://rata.digitraffic.fi/api/v1/live-trains/&lt;?php echo $juna;?&gt;',
  dataType: 'json',
  success: function(data) {
      $(row).appendTo('table.data');
      row = '';
      for (var i in data.timeTableRows) {
          row += '&lt;tr id="' + i + '"&gt;';
          row += '&lt;td&gt;' + data.timeTableRows[i].stationShortCode + '&lt;/td&gt;';
          row += '&lt;td&gt;' + data.timeTableRows[i].commercialTrack + '&lt;/td&gt;';
          row += '&lt;td&gt;' + data.timeTableRows[i].scheduledTime + '&lt;/td&gt;';
          row += '&lt;td&gt;' + data.timeTableRows[i].type + '&lt;/td&gt;';
          row += '&lt;/tr&gt;';
      }
      $(row).appendTo('table.data');
  },
  });
  &lt;/script&gt;&lt;table id="data"&gt;&lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm sure that there is/are some idiotic mistake(s), but I just can't see them myself.</p>