John
John

Reputation: 13719

PHP json_decode() not decoding JSON array

I have a JSON string in my database such as this...

a:1:{s:26:"[email protected]";s:26:"[email protected]";}

After I fetch it from the database I use the following...

$my_array = json_decode($row2['json_data']);

The problem is that I'm not getting any array from $my_array. What am I doing wrong?

I've also tried the following...

$my_array = json_decode($row2['json_data'],true);

Upvotes: 1

Views: 649

Answers (1)

jraede
jraede

Reputation: 6896

That's not a JSON string. That's a serialized array. You need to do the following:

$my_array = unserialize($row2['json_data']);

Upvotes: 10

Related Questions