任何想法爲什麼以下不起作用。php json返回布爾(false)
$request_url = "someurl?myId=$id"; //returns feed like above
$json = file_get_contents($request_url, true); //getting the file content
$decode = json_decode($json, true);
var_dump($json);
當我粘貼request_url到瀏覽器中我找回了JSON數據,但如果我嘗試在PHP中的var_dump簡直布爾(假);有任何想法嗎??
的更新和修復 確定球員感謝所有幫助。葉幫助我追蹤這一個。原來,php.ini被配置爲禁止打開網址,因此file_get_contents不起作用。我發現以下在各種網站上提到的方便功能,並將其用於排序。這是我用來幫助別人的方法。
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
不確定在讀取URL時應將第二個參數設置爲true,因爲它們不在include_path中。 [this comment](http://php.net/manual/en/function.file-get-contents.php#95665)也可能與您的問題有關 – Einacio
1)JSON無效。 2)出於某種原因,腳本無法訪問頁面,例如您需要登錄。3)請向我們顯示實際的URL,以便我們可以解決。 – lonesomeday
除了寂寞的日子,請嘗試[json_last_error()](http://php.net/manual/function.json-last-error.php) – ComFreek