无法JSON编码数组

时间:2018-02-19 12:20:55

标签: php json jsonencoder

尝试json_encode()时数组,数组不编码 我的数组是:

$jsonData = array(
        'addressId' => $addid,
        'paymentMethod' => 2,
        'transactionId' => $orderid
);
print_r($jsonData);

打印:

Array ( [addressId] => 28 [paymentMethod] => 2 [transactionId] => ORDS63375431 )

和json编码:

$jsonDataEncoded = json_encode($jsonData);
echo $jsonDataEncoded;

打印:

 {"addressId":"

我做错了什么?

这是我的完整代码:

$addid = '<script>document.write($.session.get("addid"));</script>';
    $orderid = $_POST["ORDERID"];
    $accessToken = $_COOKIE['accessToken'];
    $url = 'http://bookwise.co.in/app/api/carts/checkout';
    $ch = curl_init($url);
    $jsonData = array(
        'addressId' => $addid,
        'paymentMethod' => 2,
        'transactionId' => $orderid
    );
    print_r($jsonData);
    $jsonDataEncoded = json_encode($jsonData);
    echo $jsonDataEncoded;
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','X-API-KEY: '.$accessToken.'')); 
    $result = curl_exec($ch);

0 个答案:

没有答案