PHP json_decode不工作-显示NULL输出


PHP json_decode not working - displays NULL output

我试图使用JSON解码检索一些信息但它不工作,它只是显示数据为空当我使用var_dump

这是在URL

中传递的JSON格式数据
orderSummary={"orderInfo":[{"itemNumber":"1","quantity":"3","price":"5.99","productName":"Item_B"}]}

当我简单地回显未解码的字符串时,我得到以下

echo $_GET['orderSummary'];
//displays the following
{'"orderInfo'":[{'"itemNumber'":'"1'",'"quantity'":'"3'",'"price'":'"5.99'",'"productName'":'"Item_B'"}]}

然而,当我试图解码它的结果是空

$order = $_GET['orderSummary'];
$data = json_decode($order,true);
echo "<PRE>";
var_dump($data); die();
//displays the following
<PRE>NULL

格式不正确吗?

先通过stripslashes()运行输入字符串

$input = '{'"orderInfo'":[{'"itemNumber'":'"1'",'"quantity'":'"3'",'"price'":'"5.99'",'"productName'":'"Item_B'"}]}';
print_r(json_decode(stripslashes($input)));

stdClass Object
(
    [orderInfo] => Array
        (
            [0] => stdClass Object
                (
                    [itemNumber] => 1
                    [quantity] => 3
                    [price] => 5.99
                    [productName] => Item_B
                )
        )
)

演示

或者

关闭magic_quotes_gpc。考虑到它已被弃用(并在5.4中删除),是更好的选择