我在网站时代使用php从网址http://datos.labplc.mx/movilidad/vehiculos/436per.json创建了一个curl请求。它正在工作,即使不必回应也能回显以下数据。如果您需要了解,我们将从curl_init
开始并以curl_close
结束。
{
"consulta": {
"placa": "430PER",
"tenencias": {
"placa": "430PER",
"adeudos": "2011,2012,2013,2014,2015,2016",
"tieneadeudos": "1"
},
"infracciones": [
{
"folio": "04102237388",
"fecha": "2010-03-11",
"situacion": "No pagada",
"motivo": "POR ESTACIONARSE EN LAS VÍAS PRIMARIAS",
"fundamento": "Artículo: 12, Fracción: I, Parrafo: , Inciso: ",
"sancion": "10 unidades de cuenta "
},
{
"folio": "04092079661",
"fecha": "2009-06-19",
"situacion": "No pagada",
"motivo": "POR CERRAR U OBSTRUIR LA CIRCULACIÓN EN LA VÍA PÚBLICA CON VEHÍCULOS, PLUMAS, REJAS O CUALQUIER OTRO OBJETO.",
"fundamento": "Artículo: 14, Fracción: VII, Parrafo: , Inciso: ",
"sancion": "10 unidades de cuenta "
}
],
"verificaciones": "error"
}
}
我的问题:
如何在HTML表格中显示返回的数据,使其看起来干净可读?
答案 0 :(得分:0)
您应该使用json_decode()
。所以它将json返回到数组中,然后你可以在你的html表中使用数组和填充数据
答案 1 :(得分:0)
我主要是通过添加“pre”标记
来完成此操作echo "<pre>";
print_r($JSON);
echo "</pre>";
编辑HTML
$string = file_get_contents("http://datos.labplc.mx/movilidad/vehiculos/436per.json");
$json = json_decode($string, true);
$lines = $json['consulta']['infracciones'];
echo "<table>";
foreach($lines as $line)
{
echo "<tr>";
echo "<td>" . $line['folio'] . "</tr>";
echo "<td>" . $line['fecha'] . "</tr>";
echo "<td>" . $line['situacion'] . "</tr>";
echo "<td>" . $line['motivo'] . "</tr>";
echo "<td>" . $line['fundamento'] . "</tr>";
echo "<td>" . $line['sancion'] . "</tr>";
echo "</tr>";
}
echo "</table>";