[英]API JSON output Format
我有這個代碼
<?php
$id = $_POST['id'];
$nume = $_POST['nume'];
$rrp = $_POST['rrp'];
$pret = $_POST['pret'];
$stoc = $_POST['stoc'];
$url = $_POST['url'];
$url1 = $_POST['url1'];
$url2 = $_POST['url2'];
$url3 = $_POST['url3'];
$username = "xx@xx.eu";
$password = "aaa";
$apiUrl = "https://partners.services.aaaa.eu/v1/mkpApi/product/save";
$auth = base64_encode($username . ":" . $password);
$headers = [
"Authorization: Basic " . $auth,
"Content-Type: application/x-www-form-urlencoded",
];
$payload[] = [
"id" => $id,
"locale" => "RO",
"hidden" => 0,
"currency" => "RON",
"brand" => "Decorepublic",
"name" => $nume,
"category_id" => 10008,
"status" => "1",
"vat" => "0",
"stock" => [[
"warehouse_id" => 1,
"value" => $stoc,
]],
"sale_price" => $pret,
"rrp" => $rrp,
"description" => $nume,
"images" => [
["url" => $url],
["url" => $url1],
["url" => $url2],
["url" => $url3],
],
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(["data" => json_encode($payload)]));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$response = json_decode($result, true);
print_r($response);
//echo '<br><br>';
echo json_encode($payload);
print $stoc;
?>
在 output 我有
status":"1","vat":"0","stock":[{"warehouse_id":1,"value":"200"}]
我需要像這樣沒有""
的value
:
status":"1","vat":"0","stock":[{"warehouse_id":1,"value":200}],"
我嘗試使用print $stoc
,但它返回值 1。
我嘗試獲取 function,但它不起作用。 任何的想法?
如果您在$stoc
中有一個字符串,並且在將其編碼為 JSON 之前需要將其轉換為 integer,那么您可以使用intval 。
"value" => intval($stoc)
演示: http://sandbox.onlinephpfunctions.com/code/8b1ed16c28bfbc47f501981f2bf03f7b1bb9ce45
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.