我在MySQL中使用这种格式的JSON:
[{"name":"weekly_date","value":"19/06/2016"},{"name":"start_voucher_id","value":"1-19062016-S"},{"name":"start_time","value":"05:00"},{"name":"end_voucher_id","value":"1-19062016-E"},{"name":"end_time","value":"15:00"},{"name":"weekly_date","value":"20/06/2016"},{"name":"start_voucher_id","value":"1-20062016-S"},{"name":"start_time","value":"06:00"},{"name":"end_voucher_id","value":"1-20062016-E"},{"name":"end_time","value":"16:00"}]
我想尝试将数据转换为每个值的表格。
例如:
weekly_date:19/06/2016
weekly_date:20/06/2016
start_time:05:00
end_time:15:00
start_voucher_id:1-19062016-S
end_voucher_id:1-19062016-E
答案 0 :(得分:0)
$data = fetch_data_from_db();
$json = json_decode($data);
foreach ( $json as $key => $val )
{
echo $val->name . ': ' . $val->value . "\n";
}
请参阅此phpplayground。