Hey guys,

I am having some trouble with json_decode...
I used json_encode to encode a string that is the following:


And I am using this php code to try and get it back into an array... however its just not working... the print_r(); doesnt echo anything out at all... help pleaseee!!


    $arraydata = mysql_fetch_assoc(mysql_query("SELECT * FROM `changelog` WHERE `id` = '".$_GET['id']."'"));
    $newdata = json_decode($arraydata['newda'], true);
    $olddata = json_decode($arraydata['orig'], true);


Use var_dump instead. This will allow you to determine whether json_decode is returning null because the JSON cannot be decoded.

If you're pulling the data from a database, did you add slashes or anything when inserting?

Thanks for your reply, I added var_dunp and it returned NULL, I dont addslashes when inserting all I do it jason_encode: see below...

$thedarray = json_encode($thedarray);
    mysql_query("INSERT INTO `changelog` (`date`,`newda`,`orig`,`status`) VALUES ('".time()."','$thedarray','$orgarray','1')");

Ahhh I have a json in a json will that cause issues, if so how would you resolve it?

Why would you need a JSON string inside another JSON string?

Encode the entire data structure in one go.


How look like the above value before json_decode() function ? It contains any slash or escape ?

Its alright guys I sorted it... your right I needed to addslashes :)