Steam API将Json defindex转换为武器名称

时间:2022-02-22 16:57:53

so...

I started to develop simple tf2 inventory and get API.

我开始开发简单的tf2库存并获得API。

I'm getting the defindexs from tf2 api

我从tf2 api获得了defindexs

$link = file_get_contents("http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" . $api_key . "&steamid=" . $id . "&format=json");
$myarray = json_decode($link, true);      

print $myarray['result']['items']['0']['defindex'];

Schema from here: file_get_contents("http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=" . $api_key . "");

架构来自:file_get_contents(“http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=”。$ api_key。“”);

I printed $myarray and result is: 261

我打印了$ myarray,结果是:261

So, I have 2 questions:

所以,我有两个问题:

How I can print all defindexs to my page?

如何将所有defindex打印到我的页面?

and

How I can replace defindexs with name of weapon from GetSchema?

如何用GetSchema中的武器名称替换defindex?

1 个解决方案

#1


1  

How to print all defindexes:

如何打印所有defindexes:

Go through each item using foreach

使用foreach浏览每个项目

foreach($myarray['result']['items'] as $item)
{
    echo $item['defindex'].'<br />';
}

How to replace items defindexes by their names:

如何用名称替换项目defindexes:

Firs of all you have to add GET paramater language=en to GetSchema request link, so GetSchema will return correct item names.

首先,您必须将GET参数语言= en添加到GetSchema请求链接,因此GetSchema将返回正确的项目名称。

file_get_contents("http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?language=en&key=" . $api_key . "");

Then go through each item again like in your first question. Inside each item iterration go through each item in schema and compare defindexes. If they are match, you founded your item in schema. Print 'item_name' paramether. Don't forget about break your second foreach, because schema array is big. Example code:

然后再按照第一个问题再次浏览每个项目。在每个项目中,iterration遍历模式中的每个项目并比较defindexes。如果匹配,则在架构中创建项目。打印'item_name'参数。不要忘记打破你的第二个foreach,因为架构数组很大。示例代码:

foreach($myarray['result']['items'] as $item)
{
    foreach($schema['result']['items'] as $schemaItem)
    {
        if($item['defindex'] == $schemaItem['defindex'])
        {
            echo $schemaItem['item_name'].'<br />';
            break;
        }
    }
}

#1


1  

How to print all defindexes:

如何打印所有defindexes:

Go through each item using foreach

使用foreach浏览每个项目

foreach($myarray['result']['items'] as $item)
{
    echo $item['defindex'].'<br />';
}

How to replace items defindexes by their names:

如何用名称替换项目defindexes:

Firs of all you have to add GET paramater language=en to GetSchema request link, so GetSchema will return correct item names.

首先,您必须将GET参数语言= en添加到GetSchema请求链接,因此GetSchema将返回正确的项目名称。

file_get_contents("http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?language=en&key=" . $api_key . "");

Then go through each item again like in your first question. Inside each item iterration go through each item in schema and compare defindexes. If they are match, you founded your item in schema. Print 'item_name' paramether. Don't forget about break your second foreach, because schema array is big. Example code:

然后再按照第一个问题再次浏览每个项目。在每个项目中,iterration遍历模式中的每个项目并比较defindexes。如果匹配,则在架构中创建项目。打印'item_name'参数。不要忘记打破你的第二个foreach,因为架构数组很大。示例代码:

foreach($myarray['result']['items'] as $item)
{
    foreach($schema['result']['items'] as $schemaItem)
    {
        if($item['defindex'] == $schemaItem['defindex'])
        {
            echo $schemaItem['item_name'].'<br />';
            break;
        }
    }
}