简体   繁体   English

Json解码PHP

[英]Json Decode PHP

im trying to extract the data inside the json file, but its not working, here is my code: 我试图提取json文件中的数据,但它不起作用,这是我的代码:

JSON: JSON:

{
   "list":[
      {
         "key":"12 ano",
         "value":"12 ano"
      },
      {
         "key":"12 ano administrativo",
         "value":"12 ano administrativo"
      },
      {
         "key":"12 ano contabilidade",
         "value":"12 ano contabilidade"
      }
   ]
}

PHP: PHP:

$url = 'what.json';
$content = file_get_contents($url);
$json = json_decode($content, true);
foreach($json as $i){
    echo $i['value'];
}

您必须在foreach中调用$json['list'] ,因为如果没有它,它将在仅包含列表数组的主数组上产生循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM