如何使用HTML
数据创建表格(JSON
)?
这是我的JSON
数据:
{
"7627":
{"amt":2000,"pc":"3","bId":"1"},
"7868":
{"amt":0,"pc":"2","bId":"1"},
"7990":
{"amt":0,"pc":"2","bId":"1"},
}
答案 0 :(得分:0)
首先解码为数组:
$yourArray = json_decode($yourJsonString, true)
然后使用
构建表foreach (array_expression as $key => $value) {
echo "<tr><td> ...
编辑更新后,问题重复
这是你的json值我改成了数组
$array = json_decode{'
"7627":
{"amt":2000,"pc":"3","bId":"1"},
"7868":
{"amt":0,"pc":"2","bId":"1"},
"7990":
{"amt":0,"pc":"2","bId":"1"},
"8214":
{"amt":0,"pc":"3","bId":"1"},
"10331":
{"amt":0,"pc":"2","bId":"1"}
}', true);
之后,这是foreach使用的表视图:
echo '<table border="1px">';
foreach ($array as $key => $single){
echo '<tr>
<td>
'.$key.'
</td>
<td>
'.$single['amt'].'
</td>
<td>
'.$single['pc'].'
</td>
<td>
'.$single['bId'].'
</td>
<tr>';
}
echo '</table>';
我只是回显了这些值,如果你想改变你可以使用连接运算符表数据(td)......