2017-09-26 65 views
-5

我有一個對象從JSON deserialised這樣的:從JSON轉換成HTML表格式這樣

{ 
    "Wilayah": "BALI ", 
    "Jns_Brg": "WATER DISPANSER ", 
    "Kd_Brg": "WDP-300 ", 
    "Kd_Trn": "J", 
    "Qty": "159", 
    "Bulan": 7, 
    "Tahun": 2017 
}, { 
    "Wilayah": "BANDUNG ", 
    "Jns_Brg": "WATER DISPANSER", 
    "Kd_Brg": "WDP-300 ", 
    "Kd_Trn": "J", 
    "Qty": "2522", 
    "Bulan": 7, 
    "Tahun": 2017 
}, { 
    "Wilayah": "BANDUNG ", 
    "Jns_Brg": "BLENDER ", 
    "Kd_Brg": "BL-101 ", 
    "Kd_Trn": "J", 
    "Qty": "4554", 
    "Bulan": 7, 
    "Tahun": 2017 
} 

我想在這樣的表中顯示的數據。

Kd_Brg | Bali | Bandung 
     | 7 | 7 
======================== 
WDP-300| 159 | 2522 
BL-101 |  | 4554 

我該如何解決這個問題?後端php,前端引導jquery + html

+0

看看這個[jQuery插件](https://github.com/jongha/jquery-jsontotable)。 – brevis

回答

1
<?php 
    $json= "your json code"; 
    $data = json_decode($json); 
    if (count($data->stand)){ 
     // Open the table 
     echo "<table>"; 

     // Cycle through the array 
     foreach ($data as $key => $value) { 

      // Output a row 
      echo "<tr>"; 
      echo "<td>".$key."</td>"; 
      echo "<td>".$value."</td>"; 
      echo "</tr>"; 
     } 

     // Close the table 
     echo "</table>"; 
    } 
?> 
+0

這將是我開始爲基本表的地方。它把渲染放在服務器上,而不是你的瀏覽器(通過JS或jQuery),所以會更快地加載你的頁面。 – Luke