通过curl以指定的格式发送数据?

我有以下function之间的沟通之间的PHP和NodeJs:

function toNode($data){ //$data is array //$data example //$data = array("one"=>"yes","two"=>"no","three"=>array("yet"=>"another")) $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:'.$socket_port.'/posts'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_exec($ch); $feedback = curl_getinfo($ch); } 

这里是nodejs console.log如何接收数据:

  { one: 'yes', two: 'no', 'three[0][yet][0]':'another'} //<--- 

这里是我想要的数据出现在nodejs方面:

 { one: 'yes', two: 'no', three: [ { yet: 'another' } ] } //<--- 

我怎样才能使curl发生? 我试过在收到的信息nodejs端使用这个函数

 function urldecode(str) { return decodeURIComponent((str+'').replace(/\+/g, '%20')); } 

但它失败了,没有输出如果我没有记错的话。 此外, 用于进一步处理数据的function是来自php curl或本地在nodejs(这是不是URL编码),所以,最好的解决在PHP端的问题是正确的…可以有人帮助我这里? 非常感谢你…

编辑:包括parsing信息nodejs方面:

 app.post('/posts', function(req, res){ if(req.headers.host == '127.0.0.1:'+socket_port) { if(req.method == 'POST') { var form = new formidable.IncomingForm(); form.parse(req, function(err, fields, files) { res.writeHead(200, [[ "Content-Type", "text/plain"] , ["Content-Length", 0] ]); res.write(''); res.end(); furtherFunction(fields); }); } } }); 

我的理解是,你想发送json数据。 我没有在这里看到任何json数据。 我走了。 在这里send-json-post-using-php ,我发现如何在php中发送json数据。 希望它会有所帮助。