我从PHP开始。我想从foreach访问这些数据,但我不能。
我试图关注这篇文章,但它不起作用(How do I extract data from JSON with PHP?)。
我的数据,存储在一列
中[
{"type":"Travaux dirigés","hour":"15"},
{"type":"Travaux pratique","hour":"30"}
]
非常感谢您的帮助
答案 0 :(得分:2)
像这样解析json,live demo。
$string = '[
{"type":"Travaux dirigés","hour":"15"},
{"type":"Travaux pratique","hour":"30"}
]';
$data = json_decode($string, true);
foreach ($data as $v) {
echo $v['hour'];
}
答案 1 :(得分:0)
<?php
$data = '[
{"type":"Travaux dirigés","hour":"15"},
{"type":"Travaux pratique","hour":"30"}
]';
$getdata = json_decode($data, TRUE);
?>
<ul>
<?php
foreach($getdata as $value){
?>
<li>
<p> <?php echo $value['type']; ?>
<p> <?php echo $value['hour']; ?>
</li>
<?php
}
?>
</ul>
答案 2 :(得分:-1)
试试这个:
$json = '[
{"type":"Travaux dirigés","hour":"15"},
{"type":"Travaux pratique","hour":"30"}
]';
$data = json_decode($json);
foreach ($data as $row) {
print "row=> " . $row->hour;
}