来自 json 的 PHP 中的 Steam 库存

Steam Inventory in PHP from json

所以基本上我试图通过获取 json 内容来获取 PHP 中的 Steam 播放器库存,但我不知道该怎么做,尤其是我没有使用 json很多以前。我对我应该在 PHP 中选择什么来从 JSON.

中得到我想要的东西有疑问

PHP:

    $inventoryJsonUrl = 'http://steamcommunity.com/inventory/'.$steamID.'/730/2?l=english&count=5000';
    $inventoryJsonGet = file_get_contents($inventoryJsonUrl);
    $inventory = json_decode($inventoryJsonGet, TRUE);

for ($i=0; $i < count($inventory['assets']) ; $i++) { echo $inventory['assets']; }

假设 $inventoryJsonURL 现在是 http://steamcommunity.com/inventory/76561198260345960/730/2?l=english&count=5000

而且我在获取我想要的东西时遇到了问题,我的意思是说在 for 循环中我想要 item/skin 的名称、该项目的 ID 和其他一些东西。但我不知道如何以及我应该选择什么来获得它。

抱歉英语不好。

提前致谢。

端点包含两个列表:资产和描述。如果您真的不知道自己在寻找什么,就很难提供帮助。我认为您正在寻找的是描述,因为有所有数据。第一项见此处:https://www.dropbox.com/s/z736vu6boh9rfi6/steam1.gif?dl=0 好像是 Counterstrike GO 的霰弹枪。

此外,这篇文章可能会对您有所帮助:Getting someone's Steam inventory

首先,我建议美化 json 的内容,以便您更好地了解其中的内容。我通常使用 https://codebeautify.org/jsonviewer 但还有其他几个。

您可以使用 PHP 的 foreach 循环。

$inventories = json_decode($inventoryJsonGet , TRUE);

// you can check the structure of your array by 
// print_r($inventories)
foreach ($inventories['descriptions'] as $key => $description) {
    echo '<pre>';
    echo $description['appid'];
    echo $description['market_name'];
    echo '</pre>';
}