我嘗試從我的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無效! –