[英]file_get_contents doesn't return everything
我正在嘗試從Steamcommunity市場返回完整的json模式。 不幸的是,它僅返回第一模式。
它應該返回:{“ success”:true,“ lowest_price”:“ $ 0.63”,“ volume”:“ 5,301”,“ median_price”:“ $ 0.68”}
Instaid僅返回{“ success”:true}
<?php
$hash = "AK-47 | Elite Build (Minimal Wear)";
$marketObj = json_decode(file_get_contents("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=$hash"), true);
if ($marketObj['success'] !== true) {
echo jsonErr('An error occured while fetching market price for an item.');
return;
}else {
echo ($marketObj['lowest_price']);
}
?>
所以問題是我無法讀取腳本中的其他參數。 有人知道了嗎?
您需要urlencode()
查詢字符串,因為它在以下位置具有特殊字符:
$hash = urlencode("AK-47 | Elite Build (Minimal Wear)");
或者,您可以執行以下操作:
$url = 'http://steamcommunity.com/market/priceoverview/?' . http_build_query([
'currency' => '1',
'appid' => '730',
'market_hash_name' => 'AK-47 | Elite Build (Minimal Wear)',
]);
$marketObj = json_decode(file_get_contents($url), true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.