【发布时间】:2020-04-28 14:51:16
【问题描述】:
我有一个返回这个的 API:
[
{
"id": "5a162db4-4443-4ee8-828a-372562230bf9",
"supplyItemNumber": "PDH2OS001",
"type": "Machine",
"category": "Coolants & Lubricants",
"priority": "Alto",
"group": "Lubricants",
"description": "",
"customerUnitPrice": 0.00,
"inventoryUnit": "Litre",
"briefDescription": "",
"accountId": null,
"manufacturerCode": null,
"supplierId": null,
"manufacturerItemNumber": "",
"manufacturerItemRevision": "",
"manufacturerText": "",
"createdDate": "2018-12-11T22:57:58Z",
"createdById": "6e6a5c41-f62c-460b-96f4-fcab58381bbe",
"modifiedDate": "2019-03-06T15:46:56Z",
"modifiedById": "6e6a5c41-f62c-460b-96f4-fcab58381bbe",
"taxCodeNumber": null,
"maxQuantity": 0.00,
"minQuantity": 0.00
},
{
"id": "96d85b76-5231-4ce4-95fc-7fa9c915caab",
"supplyItemNumber": "PDH2OS002",
"type": "Machine",
"category": "Coolants & Lubricants",
"priority": "Alto",
"group": "Lubricants",
"description": "",
"customerUnitPrice": 0.00,
"inventoryUnit": "Litre",
"briefDescription": "",
"accountId": null,
"manufacturerCode": null,
"supplierId": null,
"manufacturerItemNumber": "",
"manufacturerItemRevision": "",
"manufacturerText": "",
"createdDate": "2018-12-11T22:57:58Z",
"createdById": "6e6a5c41-f62c-460b-96f4-fcab58381bbe",
"modifiedDate": "2019-03-06T15:46:45Z",
"modifiedById": "6e6a5c41-f62c-460b-96f4-fcab58381bbe",
"taxCodeNumber": null,
"maxQuantity": 0.00,
"minQuantity": 0.00
} ]
我有一个变量给我一个表格
<?PHP
if (isset($_GET['direccion']))
{
$direccion = $_GET['direccion'];
echo 'Se ha ingresado 1 direccion:' . $direccion;
}
?>
<body>
<form action="" method="GET">
<label for="direccion">Ingresar Direccion:</label>
<input type="text" name="direccion">
<button type="submit">Consultar</button>
</form>
</body>
我需要在 JSON 中搜索我在表单中输入的数据 目前我有这个
$response = curl_exec($curl);
curl_close($curl);
$response_array = json_decode($response);
//$supplyItemNumber = array_search($direccion, array_column($response_array, 'supplyItemNumber'));
foreach($response_array->id as $item)
{
if($item->id == $direccion)
{
echo $item->priority;
}
}
但是这个错误返回给我
注意:试图获取非对象的属性“id” C:\xampp\htdocs\PHP_PLEX\index.php 在第 33 行
警告:为 foreach() 提供的参数无效 C:\xampp\htdocs\PHP_PLEX\index.php 在第 33 行
【问题讨论】: