我已经尝试了数小时,用JSON数组中的数据创建一个简单的表。
下面是一个例子。我不知道为什么这段代码行不通。错误是:
“试图获取非对象的属性”。
$json_string = file_get_contents("https://bittrex.com/api/v1/public/getmarkethistory?market=BTC-HYPER&count=5");
$array = json_decode($json_string);
?>
<table><tr><th>
<?php foreach($array as $o): ?>
<tr>
<td><?php $o->result->TimeStamp ?></td>
</tr>
<?php endforeach; ?>
</table>
请查看json_string的URL以进行格式化。
或者,您可以添加第二个参数json_decode($json_string, true)
以使其成为数组而不是对象。考虑以下示例:
<?php
$json_string = file_get_contents("https://bittrex.com/api/v1/public/getmarkethistory?market=BTC-HYPER&count=5");
$array = json_decode($json_string, true);
?>
<table border="1" cellpadding="10">
<thead><tr><th>Timestamp</th></tr></thead>
<tbody>
<?php foreach($array['result'] as $key => $value): ?>
<tr>
<td><?php echo $value['TimeStamp']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句