title: reading nested JSON via AJAX with jquery or javascript and outputting to tables
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4017122/jquery-reading-nested-json">jquery reading nested json</a>  </p>
  </blockquote>
  
  
  
  <p>I would really like to have a hard and fast method to loop through multiple records in JSON, each with potentially deep nesting. I simply want to output to a table. </p>
  
  <p>I am unsure of what arguments need to be passed through the function() for either $.each() or for the javascript methodology of $.ajax() success. All examples seem to use generic words "data" or "obj" but those confuse me - are they built-in functional arguments or can I name them whatever I want like:</p>
  
  <pre><code>$.each(foo, function(bar){
  
  });
  </code></pre>
  
  <p>And how can I keep track of where I am in the loop / nest?</p>
  
  <p>I would prefer to use JQuery, but I should also know the straight-forward JavaScript method to do so. And I'd also like to know if it's possible without a hundred lines of code. </p>
  
  <p>With this JSON as an example:</p>
  
  <pre><code>{
    date: " 2012-10-18 16:58:35.104576",
    data: [{
      title: "The Princess Bride",
      rating: "PG",
      length: 128,
      stars: [
        "Gary Elwes",
        "Robin Wright",
        "Christopher Guest"
      ]
  
    }, {
      title: "This is Spinal Tap",
      rating: "R",
      length: 105,
      stars: [
        "Christopher Guest",
        "Michael McKean",
        "Harry Shearer"
      ]
    }]
  }
  </code></pre>
  
  <p>I can't find any useful examples that include nested JSON, even here in the StackOverflow.</p>
  
  <p>what's the most efficient way to loop through and assign each element to a table cell? The HTML output is not important - I know how to make a table... How do I get the "stars"?</p>
  
  <p>When I use the Chrome console and simply <code>$.getJSON('/example');</code> I get the entire JSON returned in the responseText, starting with <code>"{"date":"2012-10-18 ,"data": [{"title": "The Princess Bride",</code> However in neither the JSON docs, the JQuery docs on $.getJSON, nor in any JavaScript examples can I find a reference to <code>responseText</code>. So, I'm lost. What argument does $.getJSON need to objectify the responseText?</p>