使用jQuery和PHP更新JSON - json_decode()返回空

I'm trying to post json to a txt file but having some problems with my data. Whenever I check my data to be sent in jQuery it all looks fine, but if I print it out in php I see escape slashes and json_decode returns that data as empty. Here's the snippets of code:

jQuery

$.ajax({
    type : 'POST',
    url : 'update-json.php',
    dataType : 'json',
    data : {json : JSON.stringify([{'name':'Bob'},{'name':'Tom'}])},
    success : function(){
        console.log('success');
    },
    error : function(){
        console.log('error');
    }
});

PHP

<?php
    $json = $_POST['json'];
    $entries = json_decode($json);

    $file = fopen('data-out.txt','w');
    fwrite($file, $entries);
    fclose($file);
?>

PHP ECHO $json

[{\"name\":\"Bob\"},{\"name\":\"Tom\"}]

PHP ECHO $entries

//EMPTY

It looks like you have magic_quotes turned on in PHP. Generally you should turn this off to avoid problems like this. If you can't do that you need to call stripslashes() on your incoming string.

You can also check json_last_error() to find out why it couldn't decode.

Edit: Here's how you put in stripslashes

$json = stripslashes($_POST['json']);
$entries = json_decode($json);

if( !$entries ) {
     $error = json_last_error();
     // check the manual to match up the error to one of the constants
}
else {

    $file = fopen('data-out.txt','w');
    fwrite($file, $json);
    fclose($file);
}