0

i created a simple modifier to decode a string that is encoded in json.

function smarty_modifier_json_decode($string)
{
    return json_decode($string, true);
}

Now i have somewhere into my database a string like this:

[{"foo": "bar bar", "cool": "attr"},{"foo": "bar", "cool": "attr"},{"foo": "bar", "cool": "attr"}]

The problem is the following if i store the above string locally inside the php file in a string variable and after i run the json_decode i get back the array i should get back and works fine.

But for some reason that i dont know and idont udnertand the string that is stored into the database is probably not correctly saved in the correct character encoding, because i always get back NULL when i try to execute the fucntion on smarty:

{$data.custom6|json_decode|var_dump}

So my question is if i have this string, but i dont know how my software save it into the database what should i do to convert it into the correct encodinh and after process it with json_decode ?

Thanks

NOTE 1: i dont know how the backend is saving data into the database and i cnnot influence this step. i can only using a web interface insert my JSON string in the custom field and press a SAVE button –

NOTE 2: sorry for the mistake copying the file here, i placed $json instead $string. But it doesnt work.

4
  • NOTE: edit your question to paste notes. Commented Nov 10, 2017 at 18:03
  • $string !== $json . check and correct inside function Commented Nov 10, 2017 at 18:03
  • check this:- stackoverflow.com/questions/3408354/… Commented Nov 10, 2017 at 18:16
  • Please post the string that you get from the database (the $string you send to smarty_modifier_json_decode that returns null). Commented Nov 10, 2017 at 18:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.