I have this simple JSON string :
{"type_voie":"ALL","indice_repetition":"B","num_voie":"1","nom_voie":"Azrty","infos_voie":"Zzz","distribution_speciale":"","cp":"34230","ville":"PLAISSAN","bureau_distributeur":""}
That I get from my utf8 database.
When I pass it to json_decode($json, true)
, the result is NULL and json_last_error()
give me 4 (JSON_ERROR_SYNTAX)
If I do mb_detect_encoding, I can see that the string is in ASCII, but I only use UTF-8 everywhere.
The string was originally inserted in database from an AJAX query. I got the date from a form serialized with the jQuery function serialize().
I did this a lot in my project and never had problem like this.
I tried to force UTF8 using iconv, mb_convert_encoding or ut8_encode, but nothing change.
I also tried with html_entity_decode()
because sometimes PDO is replacing the quotes, but same result.
EDIT :
OH MY GOD. SORRY.
For some reasons, a
was concatenated between the moment I get the json and the moment I send it to the parser.
There was just PEBKAC....
I'm so ashamed.
Will delete this post soon