Javascript JSON.stringify然后作为命令行参数发送

Javascript JSON.stringify然后作为命令行参数发送,javascript,php,json,node.js,child-process,Javascript,Php,Json,Node.js,Child Process,我正在尝试创建一个NodeJS服务器,它使用child_进程对一个对象进行字符串化,并将其发送到一个php文件进行处理,然后等待结果。我的问题是,我不知道如何将数据发送到php脚本进行处理,因为当它到达脚本时,数据不再是json_可解码字符串。以下是我的NodeJs代码: dataString=JSON.stringify(data.user); child_process.exec('php '+global.defaultPath+'php_functions\\authenticate.p

我正在尝试创建一个NodeJS服务器,它使用child_进程对一个对象进行字符串化,并将其发送到一个php文件进行处理,然后等待结果。我的问题是,我不知道如何将数据发送到php脚本进行处理,因为当它到达脚本时,数据不再是json_可解码字符串。以下是我的NodeJs代码:

dataString=JSON.stringify(data.user);
child_process.exec('php '+global.defaultPath+'php_functions\\authenticate.php ' + dataString, function (err, stdout, stderr){
    if (err) {
        console.log(err);
    }
    stdout=JSON.parse(stdout);
    if (stdout.status==1) global.connections[connection.suid].uid=stdout.uid;
});
下面是authenticate.php文件的开头:

if (empty($argv[1])) {
echo "No user to authenticate...";
exit;
}

$user=json_decode($argv[1]);
php文件中的json_decode函数始终返回null,错误代码为4(语法错误)。如果在服务器脚本中记录dataString,它将返回:

{"uid":"1","accounthash":"4971b021ad2824fd42848e06bdce4d2b","suid":"xgv7-1"}
但是当它到达php脚本时,“标记丢失:

{uid:1,accounthash:4971b021ad2824fd42848e06bdce4d2b,suid:xgv7-1}
如何将javascript对象发送到PHP脚本

  • 尽量避免引用
  • 以“{}”内的字符串形式发送JSON对象
  • 例:


    是否尝试转义引号?\“?我猜shell预处理器正在删除双引号。你能试着用单引号将
    dataString
    括起来吗?@riggsfully同样的结果…@WhiteHat正在尝试
    php -f authenticate.php "{\"uid\":\"1\",\"accounthash\":\"4971b021ad2824fd42848e06bdce4d2b\",\"suid\":\"xgv7-1\"}"