title: PHP array to JavaScript using JSON object - returns null
body: <p>I've got an array in PHP which I'm passing to my view for use within the JavaScript. </p>
  
  <p>So what I've got is:</p>
  
  <pre><code>stdClass Object
  (
      [tones] =&gt; Array
      (
          [0] =&gt; Array
          (
              [id] =&gt; 114
              [sleep_session_id] =&gt; 55
              [responded_to] =&gt; 
              [in_bed] =&gt; 1
              [created] =&gt; 1316443267104
              [inserted] =&gt; 2011-09-19 14:43:04
          )
      )
  )
  
  $(function () {
      var tones = $.parseJSON(&lt;?php echo json_encode($this-&gt;tones); ?&gt;);
      alert(tones);
  });
  </code></pre>
  
  <p>Which results in something along the lines of:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function () {
          var tones = $.parseJSON([{"id":114,"sleep_session_id":55}]);
          alert(tones);
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>All I'm getting back is null, the jQuery is definately loaded and I've checked the JSON in jsonlint.com and it appears valid</p>
  
  <p>Hope you can help me out </p>
  
  <p>Andy</p>