title: why does alert(json[0].subject); give undefined?
body: <p>i have this code:</p>
  
  <pre><code> &lt;script&gt;
      $(document).ready(function()
      {
          refresh();
      });
  
      function refresh()
      {      
          $.get('getMessageDetails.php', function (json) {
              alert(json);
              alert(json[0].subject);
          },"json");
          window.setTimeout(refresh,30000);
      }   
  &lt;/script&gt;
  </code></pre>
  
  <p>then i have getMessageDetails.php:</p>
  
  <pre><code>&lt;?php
  //header('Content-Type: application/json; charset=utf-8');
  include('header_application.php');
  $lastNewMessageCnt = $obj_clean-&gt;getUnopenedMessagesCount($_SESSION['user_id']) + 1;
  $last_unopened_message_row = $obj_clean-&gt;getLastUnopenedMessage($_SESSION['user_id'],$lastNewMessageCnt); 
  echo json_encode($last_unopened_message_row); 
  ?&gt;
  </code></pre>
  
  <p>then i have the alert(json) which shows:</p>
  
  <pre><code>[{"subject":"Freechat ddd","id":"19","created_at":"2011-08-29 14:58:27","unique_code":"ALLEYCA000RC","opened_once":"0"}] 
  </code></pre>
  
  <p>which is correct</p>
  
  <p>but <code>alert(json[0].subject);</code> gives undefined???</p>
  
  <p>please help?
  thank you</p>