title: Values in UTF-8 being encoded as NULL in JSON
body: <p>I have a set of keywords that are passed through via JSON from a DB (encoded UTF-8), some of which may have special characters like é, è, ç, etc. This is used as part of an auto-completer. Example:</p>
  
  <pre><code>array('Coffee', 'Cappuccino', 'Café');
  </code></pre>
  
  <p>I should add that the array as it comes from the DB would be: </p>
  
  <pre><code>array('Coffee', 'Cappuccino', 'CafÃ©');
  </code></pre>
  
  <p>But JSON encodes as:</p>
  
  <pre><code>["coffee", "cappuccino", null];
  </code></pre>
  
  <p>If I print these via print_r(), they show up fine on a UTF-8 encoded webpage, but café comes through as "cafÃ©" if text/plain is used if I want to look at the array using print_r($array);exit();.</p>
  
  <p>If I encode using utf8_encode() before encoding to JSON, it comes through fine, but what gets printed on the webpage is "cafÃ©" and not "café".</p>
  
  <p>Also strange, but json_last_error() is being seen as an undefined function, but json_decode() and json_encode() work fine.</p>
  
  <p>Any ideas on how to get UTF-8 encoded data from the database to behave the same throughout the entire process?</p>
  
  <p>EIDT: Here is the PHP function that grabs the keywords and makes them into a single array:</p>
  
  <pre><code>private function get_keywords() 
  {
      global $db, $json;
  
      $output = array();
  
      $db-&gt;query("SELECT keywords FROM listings");
  
      while ($r = $db-&gt;get_array())
      {
          $split = explode(",", $r['keywords']);
  
          foreach ($split as $s)
          {
              $s = trim($s);
              if ($s != "" &amp;&amp; !in_array($s, $output)) $output[] = strtolower($s);
          }
      }
  
      $json-&gt;echo_json($output);
  }
  </code></pre>
  
  <p>The json::echo_json method just encodes, sets the header and prints it (for usage with Prototype)</p>
  
  <p>EDIT: DB Connection method:</p>
  
  <pre><code>function connect()
  {
  
      if ($this-&gt;set['sql_connect'])
      {
          $this-&gt;connection = @mysql_connect( $this-&gt;set['sql_host'], $this-&gt;set['sql_user'], $this-&gt;set['sql_pass'])
                  OR $this-&gt;debug( "Connection Error", mysql_errno() .": ". mysql_error());
          $this-&gt;db = @mysql_select_db( $this-&gt;set['sql_name'], $this-&gt;connection)
                  OR $this-&gt;debug( "Database Error", "Cannot Select Database '". $this-&gt;set['sql_name'] ."'");
  
          $this-&gt;is_connected = TRUE;
      }
  
      return TRUE;
  }
  </code></pre>
  
  <p>More Updates:
  Simple PHP script I ran:</p>
  
  <pre><code>echo json_encode( array("CafÃ©") ); // ["Caf\u00e9"]
  echo json_encode( array("Café") ); // null
  </code></pre>