如何在此特定输出中回显此JSON? [英] How can I echo this JSON in this specific output?
本文介绍了如何在此特定输出中回显此JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以这种格式回显此json?
How can I echo this json in this format?
123456789 - mypage3 - 2015-05-06 09:34:02
- mypage2 - 2015-05-06 09:34:02
- mypage1 - 2015-05-06 09:34:02
999999 - mypage4 - 2015-05-06 09:34:02
这是JSON
{"hash":"123456789","pages":[{"page":"mypage3","last_access_time":"2015-05-06 09:34:02"},{"page":"mypage2","last_access_time":"2015-05-06 09:34:02"},{"page":"mypage1","last_access_time":"2015-05-06 09:34:02"}]}
{"hash":"999999","pages":[{"page":"mypage4","last_access_time":"2015-05-06 09:34:02"}]}
这是我现在拥有的:
$appResult = array();
while($row = mysql_fetch_array($sql)) {
$json_res_obj = json_decode($row['json_prt']);
echo $row[json_prt];
}
推荐答案
在此处考虑此PHP代码,它仅用于第一个JSON字符串,但您可以理解:
Consider this PHP code here, it's only for the first JSON string, but you get the idea:
<?php
$json = '{
"hash": "123456789",
"pages": [
{
"page": "mypage3",
"last_access_time": "2015-05-06 09:34:02"
},
{
"page": "mypage2",
"last_access_time": "2015-05-06 09:34:02"
},
{
"page": "mypage1",
"last_access_time": "2015-05-06 09:34:02"
}
]
}';
$data = json_decode($json,true);
echo $data['hash'] . " - ";
foreach($data['pages'] as $rows) {
echo $rows['page'] . " - " . $rows['last_access_time'] . "<br>";
}
?>
这篇关于如何在此特定输出中回显此JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文