API消耗问题要么API文档不完整,要么我不理解它的实现



<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{nt"registrationNumber": "AA19AAA"n}",
CURLOPT_HTTPHEADER => array(
"x-api-key: REPLACE WITH YOUR API KEY",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
json format
{
"registrationNumber": "WN67DSO",
"taxStatus": "Untaxed",
"taxDueDate": "2017-12-25",
"artEndDate": "2007-12-25",
"motStatus": "No details held by DVLA",
"motExpiryDate": "2008-12-25",
"make": "ROVER",
"monthOfFirstDvlaRegistration": "2011-11",
"monthOfFirstRegistration": "2012-12",
"yearOfManufacture": 2004,
"engineCapacity": 1796,
"co2Emissions": 0,
"fuelType": "PETROL",
"markedForExport": true,
"colour": "Blue",
"typeApproval": "N1",
"wheelplan": "NON STANDARD",
"revenueWeight": 1640,
"realDrivingEmissions": "1",
"dateOfLastV5CIssued": "2016-12-25",
"euroStatus": "Euro 5"
}

现在我得到了代码,但我想知道Object.value,就像前面一样示例和前面的示例json格式与当前的json格式不同$make=$data[‘VehicleDetails’][‘make’];$model=$data[‘VehicleDetails’][‘model’];

function reg_form()
{
$form = "
<form method='GET' action='http://qwikcarbuyer.com/car-data'>
<input type='text' name='q'>
<input style='width:100%;margin-top:3px;' type='submit' name='submit'>
</form>
";
return $form;
}
add_shortcode('get_reg_form', 'reg_form');
function get_vehicle_api()
{

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",

=> 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{nt"registrationNumber": "AA19AAA"n}",
CURLOPT_HTTPHEADER => array(
"x-api-key: REPLACE WITH YOUR API KEY",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
实际上,我以前的json格式是嵌套的json对象,这就是我无法实现的原因。

最新更新