title: null jSON object, error Uncaught TypeError: Cannot read property 'length'
body: <p>I have a script where I get some data through JSON, this is like : </p>
  
  <pre><code>$.getJSON('phpfile', function(data) { ...
  </code></pre>
  
  <p>it works perfectly when I receive some data but when its empty, I get the next error :</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'length' of null</p>
  </blockquote>
  
  <p>Where I get this error is a line like this one :</p>
  
  <pre><code>if(data==null){
   //actions if the JSON is doesnt give me data
  }else{
   //actions if I get data
  }
  </code></pre>
  
  <p>What I want is to control when JSON sends data or not, how can I do it ?</p>
  
  <p>EDIT: I get the error with $.each(data, function(key, val) { when data is a null object, when json doesn't get any data.</p>
  
  <p>Thanks in advance</p>