How can I save a json-encoded string with international characters to the databse and then parse the decoded string in the browser?
header('Content-Type: application/json; charset=utf-8');
$j_decoded = utf8_decode(json_decode($j_encoded)); EDIT
or to be more correct $j_encoded = json_encode($j_encoded); $j_decoded = json_decode($j_encoded); no need for en/decoding utf8<meta charset="utf-8" />json utf8 encode and decode:
json_encode($data, JSON_UNESCAPED_UNICODE)
json_decode($json, false, 512, JSON_UNESCAPED_UNICODE)
force utf8 might be helpfull too: http://pastebin.com/2XKqYU49
Try sending the UTF-8 Charset header:
<?php header ('Content-type: text/html; charset=utf-8'); ?>
And the HTML meta:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
For me both methods
<?php
header('Content-Type: text/html; charset=utf-8');
echo json_encode($YourData, \JSON_UNESCAPED_UNICODE);
if you get "unexpected Character" error you should check if there is a BOM (Byte Order Marker saved into your utf-8 json. You can either remove the first character or save if without BOM.