嗨,我想把一個嵌套的JSON陣列資料讀到一個表中,并作為一個串列,而不僅僅是一行。
你看,它出來的方式。

鏈接到JSON:JSONURL-DOC
我試圖達到的JSON代碼:
"EquipmentList"。 [ "ABSBrakes", "Alarm"。 "AlloyRims", "antiSpin"。 "AutomaticGear",/span> "RemoteCentralLocking", "PoweredWindows"。 "PoweredMirrorsHeated", "CruiseControl", "InfoCenter", "AutomaticClimateControl"。 "TripComputer", "Navigation", "GearShiftStearingWheel",/span> "ServiceOK"。 "Immobilizer",/span> "SeatHeater", "XenonLight" ]
到目前為止,我的代碼非常簡單,因為我很難將資料列在一個串列中,即LI或TABLE中。
<?php
$url = 'https://gw.bilinfo.net/listingapi/api/export'/span>;
//在此提供您的用戶名和密碼。
$auth = base64_encode("demo:ocfB6XzF73") 。
//創建具有基本認證的HTTP背景關系。
$context = stream_context_create([
'http' => ['header' => "授權。Basic $auth"] 。
]);
//>查詢資料
$data = file_get_contents($url, false, $context) 。
//$escaped = json_encode($data);
$escaped = json_decode($data); /, JSON_FORCE_OBJECT
/*初始化臨時變數以動態設計表格*/。
$temp = "<table>"/span>;
/*根據JSON記錄定義表的列頭*/。
$temp .= "<tr>"/span>;
$temp .= "<th> Bil</th>";
$temp .= "<th>Model</th>";
$temp .= "<th>Motor</th>";
$temp .= "<th>Drivmiddel</th>";
$temp .= "<th>Udstyr</th>"/span>;
$temp .= "<th>Billeder</th>"/span>;
$temp .= "</tr>";
/*動態生成行& 列*/。
foreach ($escaped->車輛 as $vehicle) {
$temp .= "<tr>"/span>;
$temp .= "<td>" . $vehicle-> Make . "</td>";
$temp .= "<td>" . $vehicle-> Model . "</td>";
$temp .= "<td>" . $vehicle-> Motor . "</td>";
$temp .= "<td>" . $vehicle->推進劑 . "</td>";
foreach($escaped->車輛[0]->設備串列 as $EquipmentItem){
$temp .= "<td>"/span> . $EquipmentItem . "</td>"。
}
for ($p = 0; $p < $vehicle-> PictureCount; $p ) {
$temp .= "<td><img src='"/span> . $vehicle->圖片[0] 。"'></td>"。
}
}
$temp .= "</tr>"/span>;
/*表的結束標簽*/。
$temp .= "</table>"/span>;
/*列印保存表格的臨時變數*/。
echo $temp;
echo $data;
? >
uj5u.com熱心網友回復:
在Anand Pandey的幫助下,
<?php
$url = 'https://gw.bilinfo.net/listingapi/api/export'/span>;
//在此提供您的用戶名和密碼。
$auth = base64_encode("demo:ocfB6XzF73") 。
//創建具有基本認證的HTTP背景關系。
$context = stream_context_create([
'http' => ['header' => "授權。Basic $auth"] 。
]);
//>查詢資料
$data = file_get_contents($url, false, $context) 。
//$escaped = json_encode($data);
$escaped = json_decode($data); /, JSON_FORCE_OBJECT
/*初始化臨時變數以動態設計表*/。
$temp = "<table class='car-list' >";
/*根據JSON記錄定義表的列標題*/。
$temp .= "<tr>"/span>;
$temp .= "<th class='th-style'>Bil</th>"/span>;
$temp .= "<th class='th-style'>Model</th>"/span>;
$temp .= "<th class='th-style'> Motor</th>";
$temp .= "<th class='th-style'>Drivmiddel</th>"/span>;
$temp .= "<th class='th-style'>Udstyr</th>"/span>;
$temp .= "<th class='th-style'>Billeder</th>"/span>;
$temp .= "</tr>";
/*動態生成行& 列*/。
foreach ($escaped->車輛 as $vehicle) {
$temp .= "<tr>"/span>;
$temp .= "<td class='td-style'>". $vehicle-> Make . "</td>"。
$temp .= "<td class='td-style'>" . $vehicle-> Model . "</td>"。
$temp .= "<td class='td-style'>" . $vehicle-> Motor . "</td>"。
$temp .= "<td class='td-style'>" . $vehicle->推進劑 . "</td>";
$temp .= "<td class='td-style'>";
foreach ($escaped->車輛[0]->設備串列 as $EquipmentItem) {
$temp .= "<table>"/span>;
$temp .= "<tr>";
$temp .= "<td class='equipmentlist'>" . $EquipmentItem . "</td>"。
$temp .= "</tr>";
$temp .= "</table>";
}
$temp .= "</td>";
$temp .= "<td class='td-style'>";
for ($p = 0; $p < $vehicle-> PictureCount; $p ) {
$temp .= "<table>"/span>;
$temp .= "<tr>";
$temp .= "<td class='td-style'>";
$temp .= "<img class='cc-images' src='". $vehicle->圖片[$p] 。" '>";
$temp .= "</td>";
$temp .= "</tr>";
$temp .= "</table>";
}
$temp .= "</td>";
}
$temp .= "</tr>";
/*表的結束標簽*/。
$temp .= "</table>"/span>;
/*列印保存表格的臨時變數*/。
echo $temp;
//echo $data;
? >
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/309973.html
標籤:
上一篇:計算資料集串列的相關矩陣
