您的位置:首页 > 编程语言 > PHP开发

php json_decode解析json文件问题。

2017-03-25 17:33 555 查看
 怎样能将下面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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: