Re: [PHP] json_decode mistery

[email protected] (Matijn Woudt)
Newsgroups php.general
Message-ID <CAC_gtuPus_HOqQoYWj4o8GrUMs-dE+xu8Yhs+ekubwWfsVQ_bg@mail.gmail.com>
On Fri, May 24, 2013 at 9:06 AM, Radek Krejča <[email protected]>wrote:

> Hello, I am usin json regulary, but in one script I have mistery:
>
> echo($decrypted_data)."\n\n";
> var_dump(json_decode($decrypted_data, true));
> echo "\n";
> var_dump(json_decode('{"result_ok":true,"result_message":null,"client_name":"Radek
> Krej\u010da"}', true));
>
> I got:
>
> {"result_ok":true,"result_message":null,"client_name":"Radek Krej\u010da"}
>
> NULL
>
> array(3) {
>   ["result_ok"]=>
>   bool(true)
>   ["result_message"]=>
>   NULL
>   ["client_name"]=>      a"
> } string(13) "Radek KrejÄ
>
>
> You can see, that in $decrypted_data, is stored valid (by my opinion) json
> data. If I use this variable in json_decode, I got "null". And if I manualy
> use data displayed on screen, I got valid array.
>
> Where I do mistake? If I remove client_name (so no utf8 is in json data),
> situation is the same.
>
> Radek
>

Hi,

It could be there are NUL-bytes or other unprintable ASCII characters in
the original $decrypted_data.
Try this:
var_dump(json_encode($decrypted_data));
Yes, json_encode, as it will show \u0000 or any other low unicode value.

- Matijn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.