PHP函数json_decode不会解码PHP中的有效json


PHP function json_decode will not decode valid JSON in PHP

我想用PHP解析JSON。函数:json_decode不返回任何内容。

这是我的index.php文件。

<?php
  $jsondata = file_get_contents("test.json");
  $json = json_decode($jsondata,true);
  echo $json['movies'][0]['title'];
?>

这是我的test.json文件

{
    "movies":[
            { 
              "title": "Godfather",
              "Genre": "Action",
              "Language": "English"
            }
         ]
}

浏览器没有显示任何响应。我希望它能打印Godfather

php版本中未启用JSON支持。请运行<?php phpinfo()进行检查在PHP 5.2 中添加了JSON函数

http://php.net/manual/en/function.json-encode.php

http://php.net/manual/en/function.json-decode.php

您需要将PHP版本更新到至少5.2以上才能使用json函数。