title: Jquery, JSON parsing
body: <p>I have a JSON packet that is not just 'data' - there is some metadata associated with it - but I can't seem to reference that...</p>
  
  <p>Here's what it looks like (the JSON)</p>
  
  <pre><code>{ "count":"4",
    "companies": [
  { "id":"1", "company":"Acme", "address":"1234 street st.", "city":"New York", "state":"NY", "zip":"02123", "phone":"212-222-2222", "contact":"Billy Bob", "email":"bb@ny.com", "jobscurrent":"12", "jobsdone":"11" },
  { "id":"3", "company":"Acme", "address":"1234 street st.", "city":"New York", "state":"NY", "zip":"02123", "phone":"212-222-2222", "contact":"Billy Bob", "email":"bb@ny.com", "jobscurrent":"12", "jobsdone":"11" },
  { "id":"4", "company":"Acme", "address":"1234 street st.", "city":"New York", "state":"NY", "zip":"02123", "phone":"212-222-2222", "contact":"Billy Bob", "email":"bb@ny.com", "jobscurrent":"12", "jobsdone":"11" },
  { "id":"5", "company":"Acme", "address":"1234 street st.", "city":"New York", "state":"NY", "zip":"02123", "phone":"212-222-2222", "contact":"Billy Bob", "email":"bb@ny.com", "jobscurrent":"12", "jobsdone":"11" }
  ] }
  </code></pre>
  
  <p>Here is what my jQuery looks like...
  Nested "each" - the first one (it's my understanding) is looping over {count,companies}
  and the one nested inside that is looping over each array in the customers array....</p>
  
  <p>The second one is working fine (and works fine even if i don't nest it inside the first one - 
  However I need to pass back something like "displaying n records" - but right now, the "value.count"</p>
  
  <pre><code>items.push('&lt;tr class=""&gt;&lt;td colspan="11"&gt;' + value.count + '&lt;/td&gt;&lt;/tr&gt;' );
  </code></pre>
  
  <p>returns "UNDEFINED"</p>
  
  <p>UGH! - and I just noticed it's giving me my output twice... which I guess is to be expected - once for each iteration of the outside loop - since I have 2 elements</p>
  
  <p>SO the question is - how can I reference my meta data once... obviously I don't wnat to use the EACH
  for that..</p>
  
  <p>I tried just "data.count" to reference it - but I got nothing, which is why I went to the "EACH" way of extracting JSON vars...</p>
  
  <pre><code>function loadTable() {
      $.ajax({
          type: 'POST',   
          url: 'company_list.php',    
          dataType: 'json',   
          success: function ( data ) {                
              var items = [];
              var line = 1;
  
              $.each( data, function ( key, value ) {
                  // meta data
                  items.push('&lt;tr class=""&gt;&lt;td colspan="11"&gt;' + value.count + '&lt;/td&gt;&lt;/tr&gt;' );
  
                  // the real data
                  $.each( data.companies, function ( key, value ) {   
                      var thisRowClass = 'odd';
                      if ( line % 2 ) {
                          thisRowClass = 'even';
                      }
                      items.push('&lt;tr class="' + thisRowClass + '"&gt;&lt;td&gt;'  + value.company + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.address + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.city + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.state + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.zip + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.phone + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.contact + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.email + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.jobscurrent + 
                                 '&lt;/td&gt;&lt;td&gt;' + value.jobsdone + 
                                 '&lt;/td&gt;&lt;td&gt; edit | delete ' +
                                 '&lt;/td&gt;&lt;/tr&gt;');   
                      line++;
                  }); 
              });
  
              //$( '#message' ).html( '&lt;p&gt;Displaying' + value.count + '&lt;/p&gt;' );   
              $( '#companies-list' ).append( items.join('') );                                   
  
          },
  
          error: function () {    
              // there's an error
              $( '#message' ).html( '&lt;p&gt;There was a problem on the server... &lt;/p&gt;' ); 
          }
      });
  }
  </code></pre>