我尝试从我的JSON文件加载数据到php,但我的oupt是emtpy什么是错误?PHP加载json数据,输出为空
JSON:
{
"drinks":[
"1" {"coffee": "zwart", "country":"afrika"},
"2" {"tea": "thee", "country":"china"},
"3" {"water": "water", "country":"netherlands"},
]
}
PHP:
<?php
$str = file_get_contents('data.json');
$json = json_decode($str, true);
$drinks = $json['drinks'][0][coffee];
echo $drinks;
?>
尝试添加冒号在'“1”之后''像这样:'“1”:{....' – Veniamin
看起来像这个json是无效的。 –
Json无效! –