file_get_contents 不是 return 一切
file_get_contents doesn't return everything
我正在尝试 return 来自 steamcommunity 市场的完整 json 模式。
不幸的是,它只是 return 第一个模式。
它应该 return : {"success":true,"lowest_price":"$0.63","volume":"5,301","median_price":"$0.68 "}
仅插入 returns {"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);
我正在尝试 return 来自 steamcommunity 市场的完整 json 模式。 不幸的是,它只是 return 第一个模式。
它应该 return : {"success":true,"lowest_price":"$0.63","volume":"5,301","median_price":"$0.68 "}
仅插入 returns {"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);