0

I have a JSON array that saves some accented characters in it, a value could be üna. Saving this as JSON i use json_encode($array, JSON_UNESCAPED_UNICODE); which works correctly, however when trying to display on the page with json_decode() it will not show because of the accent.

$arr = json_decode($array, true);
print_r($arr);

I have tried adding the JSON_UNESCAPED_UNICODE to that aswell as adding a UTF-8 header line but nothing will print out.

  • Possible duplicate of [How to json\_encode array with french accents?](https://stackoverflow.com/questions/6928982/how-to-json-encode-array-with-french-accents) – William Perron May 04 '18 at 13:06

1 Answers1

1

JSON_UNESCAPED_UNICODE Encodes multibyte Unicode characters literally, this will do it

$arr=array("üna","&8*");
$encode_json = json_encode($arr,JSON_UNESCAPED_UNICODE);
print_r($encode_json);
$decode_json=json_decode($encode_json);
print_r($decode_json);
  • When trying this with my array, the accent comes out as `u00c3u00bc` so doesn't work correctly – Brendan Mullan May 04 '18 at 12:46
  • 1
    @BrendanMullan it looks ok to me: https://eval.in/999371 . Perhaps your page isn't set up for UTF8. Make sure your page starts something like ` ` - see https://www.w3.org/International/questions/qa-html-encoding-declarations – ADyson May 04 '18 at 13:26