Why is PHP json_decode on JSON loaded from a database not working?
one text
Solution:
So, if i understand the problem correctly, you encode the data (becomes a string) and store it. Then you retrieve the string and decodes it. It becomes a string again?
- When you say "echo" it, are you actually using echo? (because if you are expecting it to become object or array, you actually shouldn't use echo)
- Are you storing it as UTF-8 in the database? - the JSON accepted by json_decode must be UTF8
Most likely, you should look into the string escaping on insert and retrieval. See https://www.php.net/manual/en/pdo.quote.php
(always prepare statements: https://www.php.net/manual/en/pdo.prepare.php)
Source