0

尝试 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);
4

0 回答 0