這是我嘗試使用PHP解碼的JSON,但出現問題。請檢查我的代碼如下。T_DNUMBER解碼PHP中的JSON時出錯
{ "146505212039213_2962095710480135": {
"reactions_like": {
"data": [
],
"summary": {
"total_count": 172595
}
},
"reactions_love": {
"data": [
],
"summary": {
"total_count": 75252
}
},
"reactions_haha": {
"data": [
],
"summary": {
"total_count": 132
}
},
"id": "146505212039213_2962095710480135"
}}
代碼我使用:
function curl_get_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$json = curl_get_contents('URL HERE');
$data = json_decode($json);
echo $data->146505212039213_2962095710480135->reactions_like->summary->total_count;
這是我收到的錯誤:
Parse error: syntax error, unexpected '146505212039213' (T_DNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\test.php on line 13
什麼,我做錯了什麼?
錯誤之類的了答案: 「預期標識符(T_STRING)」。像'12_34'這樣的東西不是數字。看看如何[使用特殊字符訪問屬性](https://duckduckgo.com/?q=php+access+property+with+special+characters) – mario
重新打開,因爲對於wiki帖子中的T_DNUMBER沒有好的答案。 – Sammitch