簡體   English   中英

在PHP中解析JSON沒有給出響應

[英]Parsing JSON in PHP is not giving response

因此,我試圖從JSON文件中獲取一些信息。 但是由於某種原因,對於我所需的信息沒有實際的響應。

這是我正在運行的代碼。

$json_object = file_get_contents('http://steamcommunity.com/profiles/'.$steamID.'/inventory/json/730/2');
$json_decoded = json_decode($json_object); 
echo $json_decoded->success;

我從cookie中獲取了steamID。 但是,如果您想查看JSON的外觀,則可以查看以下鏈接: http : //steamcommunity.com/profiles/76561198031313244/inventory/json/730/2

問題是您正在檢查的URL被重定向到另一個URL, file_get_contents()不支持以下重定向AFAIK,因此您最好使用cURL

檢查此答案https://stackoverflow.com/a/4324018/5658508

問題就像其他人告訴您的那樣,在此鏈接中http://steamcommunity.com/profiles/76561198031313244/inventory/json/730/2

我只是監視響應,所以當您訪問該鏈接時,您會收到一個302 Moved Temporarily http響應,該響應是新鏈接http://steamcommunity.com/id/SANDISS/inventory/json/730/2

如果您不僅擁有鏈接的鏈接,可以嘗試使用file_get_contents獲取內容,或者使用curl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM