php json_decode解析json文件问题。

勇zhe无wei 2015-04-08 03:23:07
怎样能将下面json的格式的value一个一个的用echo显示出来?谢谢

<?php
$json_file = "list.json";
$handle = fopen($json_file , "r");
$contents = fread($handle,filesize($json_file));
fclose($handle);
// $js = json_decode($contents);
// print_r $js;
foreach (range(4, 3, -1) as $depth) {
var_dump(json_decode($contents, true, $depth));
}
?>


输出结果:

array(3) {
["traffic.statistics"]=>
array(2) {
["ethernet.bytes"]=>
int(1901)
["low.protos"]=>
int(2)
}
["detected.protos"]=>
array(2) {
[0]=>
array(4) {
["name"]=>
string(6) "DHCPV6"
["packets"]=>
int(1)
["bytes"]=>
int(149)
["flows"]=>
int(1)
}
[1]=>
array(4) {
["name"]=>
string(5) "LLMNR"
["packets"]=>
int(4)
["bytes"]=>
int(296)
["flows"]=>
int(2)
}
}
["known.flows"]=>
array(0) {
}
}
NULL
...全文
225 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
勇zhe无wei 2015-06-23
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning的回复:
贴出 list.json 文件内容
谢谢,我已解决
勇zhe无wei 2015-06-23
  • 打赏
  • 举报
回复
引用 2 楼 沪php攻城师的回复:
foreach遍历
谢谢
沪php攻城师 2015-04-08
  • 打赏
  • 举报
回复
foreach遍历
xuzuning 2015-04-08
  • 打赏
  • 举报
回复
贴出 list.json 文件内容

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧