我想用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 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函数。