JSON-jquery到php;如何发布数据

JSON-jquery到php;如何发布数据,php,jquery,symfony,Php,Jquery,Symfony,我有一个JSON对象(postData)要发送到我的PHP web服务 $.ajax({ url: postLink, type: 'POST', data: JSON.stringify(postData), complete: function () { console.log('COMPLETE: tried to send json'); }, success: function (data) { conso

我有一个JSON对象(
postData
)要发送到我的PHP web服务

$.ajax({
    url: postLink,
    type: 'POST',
    data: JSON.stringify(postData),
    complete: function () {
        console.log('COMPLETE: tried to send json');
    },
    success: function (data) {
        console.log("Success" + data);
        if (data.success) {
             // do something
        }
    },
    error: function (error) {
        console.log("ERROR" + error);
    }
});
在PHP(Symfony)中,我这样读:

$content = htmlspecialchars_decode($this->get('request')->getContent(), ENT_NOQUOTES);
$data = array();

if (!empty($content))
{
    $data = json_decode($content, true);

    var_dump($content);
我在
json\u解码上收到一个内部服务器错误。我相信这是因为(根据我的
var_dump
)JSON通过Web服务看起来是这样的:

"auth":{"username":" ...
我甚至尝试添加
htmlspecialchars\u decode
以将这些引用转换回
“…但它仍然返回为
”`


我不知道该怎么办。因此,任何想法都非常受欢迎。

删除
htmlspecialchars\u解码

使用:


所有的问题都是因为JSON.stringify(postData)
。你真的需要这个吗?

JSON.stringify
创建一个HTML可打印字符串。你的帖子数据来自哪里?尝试在表单上使用
serialize
serializeArray
。是否可以记录:JSON.stringify(postData)。如果您发送一个json对象,php会像他在问题中提到的数组(如果是js对象)一样理解它,他“尝试”了
htmlspecialchars\u解码。这应该是一个评论。
$content = html_entity_decode($this->get('request')->getContent());
$data = json_decode($content);