I have a text coming from a CSV full of accent marks. I check if mb_check_encoding($my_text, 'utf-8')
is true, and yes, it is. With this text I generate a variable $json
which apply a
json_encode($json,JSON_NUMERIC_CHECK);
var_dump($json)
gives an array of arrays with all strange marks correct (é, ì, etc), but the generated JSON text is incorrect (ex: "Donn\ées"
instead of "Données"
).
I know that json_encode
only works fine for utf8 encoded data, that's why I checked it before that it was utf8. I tried also adding a header("Content-type: application/json; charset=UTF-8");
without success.
Then what could be the reason of that?
This is how JSON encodes "strange marks", ie Unicode characters. When you use json_decode()
on your JSON-encoded string, it will return to normal.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.