Reputation: 3262
I'm trying the following code:
header('Content-type: application/json; charset=UTF-8');
$val = array('code' => 1, 'message' => 'Não encontrado!');
$res = json_encode( $val );
echo $res;
The answer is:
{ "code" : 1, "message" : "N\u00e3o encontrado!" }
I searched, but I couldn't find an aswer to this problem. I think it's an UTF-8 encode issue. My source file is encoded with UTF-8. Any idea?
Upvotes: 0
Views: 151
Reputation: 224857
That’s not a problem. \u00e3
represents ã in JSON.
js> 'ã'.charCodeAt(0).toString(16)
"e3"
If you really need it, though, you can tell PHP not to escape it:
$res = json_encode($val, JSON_UNESCAPED_UNICODE);
Upvotes: 6