title: Uncaught TypeError: Cannot read property 'length' of undefined while accessing arraylist through Json Object
body: <p>I am returning an array list from my struts2 action class. 
  When I an trying to access that Array list in my JavaScript file through JSON,</p>
  
  <p>I am getting</p>
  
  <blockquote>
    <p>"Uncaught TypeError: Cannot read property 'length' of undefined".  </p>
  </blockquote>
  
  <p>in below line <code>json.EmpListByOffsetAndLength</code></p>
  
  <p>See my code below. I want to display data that is in <code>arraylist</code> into the table in my jsp page.</p>
  
  <pre><code>alert(url);
  $.ajax({
      type : "POST",
      cache : false,
      url : url,
      success : function(json) {
          var table = document.getElementById("tablereload");
          var rowCount = document.getElementById("tablereload").rows.length;
  
          alert("this is row count" +rowCount);
  
          $("#test").html('');
  
          $.each(json.EmpListByOffsetAndLength, function(index, value) {
              var row = table.insertRow(rowCount);
              var i = 0;
  
              for ( var key in value) {
                  var val = value[key];
  
                  alert(val);
                  var cell = row.insertCell(i);
  
                  var div = document.createElement('div'), // create
                  // DIV
                  // element
                  txt = document.createTextNode(val); // create
                  // text
                  // node
                  div.appendChild(txt);
                  cell.appendChild(div);
  
                  i++;
              }
          });
      }
  }) 
  </code></pre>