Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

PHP's json_decode Returns Null?

Update:

PHP CODE:

$a = array ('x'=>'xex');

var_dump($a); //output: array(1) { ["x"]=> string(3) "xex" }

echo (json_encode($a)); //output: {"x":"xex"}

$a = array ('x'=>'xéx');

var_dump($a); //output: array(1) { ["x"]=> string(3) "xéx" }

echo (json_encode($a));

The last line of code produces no output, not even "null". Can you help me understand this behaviour?

3 Answers

Relevance
  • ?
    Lv 4
    4 years ago

    Php Json_encode Null

  • Chris
    Lv 7
    6 years ago

    Here's what I get: {"x":"x\u00e9x"}

    http://ideone.com/SfexHb

    The data must be in utf-8 format, which means you have to save the PHP file as Unicode, not ANSI.

    If your editor doesn't support choosing the encoding, switch to one that does, like Notepad++.

  • 6 years ago

    Thanks, too, to json_last_error() for helping me figure it all out.

Still have questions? Get your answers by asking now.