【发布时间】:2017-04-09 21:20:21
【问题描述】:
我使用引导数据表在表中显示来自 API 的数据。这是数据:
{
"response_status": {
"status_code": 0,
"status_message": [
{
"reg_number": "123",
"company": "Company A",
"office": "Orlando",
"phone_number": "28122312345",
"postal_address": "000",
"postal_code": "000"
},
{
"reg_number": "552",
"company": "Company B",
"office": "Miami",
"phone_number": "28122312345",
"postal_address": "000",
"postal_code": "000"
},
{
"reg_number": "154",
"company": "Company C",
"office": "San Francisco",
"phone_number": "28122312345",
"postal_address": "000",
"postal_code": "000"
}
]
}
}
我需要这样输出 html 的结果:
<table>
<thead>
<tr>
<th>Reg No</th>
<th>Company</th>
<th>Office</th>
<th>Phone Number</th>
<th>Postal Address</th>
<th>Postal Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td>Company A</td>
<td>San Francisco</td>
<td>28122312345</td>
<td>000</td>
<td>000</td>
</tr>
<tr>
<td>552</td>
<td>Company B</td>
<td>Miami</td>
<td>28122312345</td>
<td>000</td>
<td>000</td>
</tr>
<tr>
<td>154</td>
<td>Company C</td>
<td>San Francisco</td>
<td>28122312345</td>
<td>000</td>
<td>000</td>
</tr>
</tbody>
<table>
有没有一种方法可以遍历 JSON 正文,并使用 php foreach 循环将 "status_message": []; 之间的所有字段的循环自动输出到我的表?
【问题讨论】: