문제

At the moment im getting a json reponse when i query http://api.steampowered.com/IEconItems_{appid}/GetPlayerItems/v0001/?key={apikey}&steamid={steamid}&format=json

The problem however is that i dont know what to do with this reponse without any aditional info that i cant find anywhere. A part of response im getting when looking at my own cs:go inventory:

            {
            "id": 235322185,
            "original_id": 190991409,
            "defindex": 19,
            "level": 1,
            "quality": 4,
            "inventory": 70,
            "quantity": 1,
            "rarity": 4,
            "attributes": [
                {
                    "defindex": 6,
                    "value": 1130627072,
                    "float_value": 228
                },
                {
                    "defindex": 7,
                    "value": 1148436480,
                    "float_value": 975
                },
                {
                    "defindex": 8,
                    "value": 1031063904,
                    "float_value": 0.059762358665466309
                },
                {
                    "defindex": 147,
                    "value": "models\/weapons\/stattrack.mdl"
                },
                {
                    "defindex": 145,
                    "value": "models\/weapons\/w_smg_p90_mag.mdl"
                }
            ]

        },
        {
            "id": 236527226,
            "original_id": 236502674,
            "defindex": 27,
            "level": 1,
            "quality": 9,
            "inventory": 82,
            "quantity": 1,
            "rarity": 3,
            "attributes": [
                {
                    "defindex": 6,
                    "value": 1133608960,
                    "float_value": 291
                },
                {
                    "defindex": 7,
                    "value": 1142240880,
                    "float_value": 596.8505859375
                },
                {
                    "defindex": 8,
                    "value": 994750258,
                    "float_value": 0.0030927178449928761
                },
                {
                    "defindex": 80,
                    "value": 0,
                    "float_value": 0
                },
                {
                    "defindex": 81,
                    "value": 0,
                    "float_value": 0
                },
                {
                    "defindex": 147,
                    "value": "models\/weapons\/stattrack.mdl"
                },
                {
                    "defindex": 145,
                    "value": "models\/weapons\/w_shot_mag7_mag.mdl"
                }
            ]

        },
        {
            "id": 236529059,
            "original_id": 136971214,
            "defindex": 35,
            "level": 1,
            "quality": 4,
            "inventory": 77,
            "quantity": 1,
            "rarity": 2,
            "attributes": [
                {
                    "defindex": 6,
                    "value": 1077936128,
                    "float_value": 3
                },
                {
                    "defindex": 7,
                    "value": 1141712676,
                    "float_value": 564.611572265625
                },
                {
                    "defindex": 8,
                    "value": 1031160533,
                    "float_value": 0.060122329741716385
                },
                {
                    "defindex": 147,
                    "value": "models\/weapons\/stattrack.mdl"
                }
            ]

        }

The id's correnspond with the weapons and the rarity and quantity makes sense too. But i cant be expected to manually find every id of every weapon in every state right? Am i missing a different API that i can use to see what weapon corrensponds with what id?

ps: Sorry for bad english

도움이 되었습니까?

해결책

You will call the GetSchema to determine which items these are. You'll compare DefIndex values against the ones returned by GetSchema

Your work flow will look like this:

  • Call GetSchema and store result of result['items'] some place to look up later
  • Call your current call and parse through the items. For each item, look up a result in your stored value from above
  • GetSchema also has rarities and other values you may need (ie. those attributes)

다른 팁

Compare your inventory defindex (not attributes) value with this schema.

http://api.steampowered.com/IEconItems_730/GetSchema/v0002/?key=xxxxx

For example,defindex = 19 is weapon_p90 on schema.

Try to parse JSON strings into an array. Because this response is not totaly a valid JSON string try to insert this into a new array to parse a valid JSON string.

Such as: {"main_container": [ --> YOUR POSTED CODE <-- ]}

<?php

    $jsonResponse = '{"main_container": [
                {
                "id": 235322185,
                "original_id": 190991409,
                "defindex": 19,
                "level": 1,
                "quality": 4,
                "inventory": 70,
                "quantity": 1,
                "rarity": 4,
                "attributes": [
                    {
                        "defindex": 6,
                        "value": 1130627072,
                        "float_value": 228
                    },
                    {
                        "defindex": 7,
                        "value": 1148436480,
                        "float_value": 975
                    },
                    {
                        "defindex": 8,
                        "value": 1031063904,
                        "float_value": 0.059762358665466309
                    },
                    {
                        "defindex": 147,
                        "value": "models\/weapons\/stattrack.mdl"
                    },
                    {
                        "defindex": 145,
                        "value": "models\/weapons\/w_smg_p90_mag.mdl"
                    }
                ]

            },
            {
                "id": 236527226,
                "original_id": 236502674,
                "defindex": 27,
                "level": 1,
                "quality": 9,
                "inventory": 82,
                "quantity": 1,
                "rarity": 3,
                "attributes": [
                    {
                        "defindex": 6,
                        "value": 1133608960,
                        "float_value": 291
                    },
                    {
                        "defindex": 7,
                        "value": 1142240880,
                        "float_value": 596.8505859375
                    },
                    {
                        "defindex": 8,
                        "value": 994750258,
                        "float_value": 0.0030927178449928761
                    },
                    {
                        "defindex": 80,
                        "value": 0,
                        "float_value": 0
                    },
                    {
                        "defindex": 81,
                        "value": 0,
                        "float_value": 0
                    },
                    {
                        "defindex": 147,
                        "value": "models\/weapons\/stattrack.mdl"
                    },
                    {
                        "defindex": 145,
                        "value": "models\/weapons\/w_shot_mag7_mag.mdl"
                    }
                ]

            },
            {
                "id": 236529059,
                "original_id": 136971214,
                "defindex": 35,
                "level": 1,
                "quality": 4,
                "inventory": 77,
                "quantity": 1,
                "rarity": 2,
                "attributes": [
                    {
                        "defindex": 6,
                        "value": 1077936128,
                        "float_value": 3
                    },
                    {
                        "defindex": 7,
                        "value": 1141712676,
                        "float_value": 564.611572265625
                    },
                    {
                        "defindex": 8,
                        "value": 1031160533,
                        "float_value": 0.060122329741716385
                    },
                    {
                        "defindex": 147,
                        "value": "models\/weapons\/stattrack.mdl"
                    }
                ]

            }
        ]}
    ';

    $jsonDecodeArray = json_decode($jsonResponse, true);

    foreach($jsonDecodeArray as $mainContainerItems){

        // LOOP THROUGH ALL ITEM GROUP. IN THIS CASE WE HAVE 3 ITEM GROUPS IN
        // $mainContainerItems ARRAY

        foreach($mainContainerItems as $inventoryItem){

            echo $inventoryItem['id']; // will return for example: 236529059
            echo $inventoryItem['original_id']; // will return for example: 136971214
            echo $inventoryItem['defindex'];
        }       
    }
?>

In this case the resoult will be a multi dimensional array, where you can loop through with multiple foreach.

The resoult is:

$jsonDecodeArray contains the main_container array with all items, where a single item is also an array.

$inventoryItem contains a single item with it's all properties. Like shown below.

Array
(
    [id] => 236529059
    [original_id] => 136971214
    [defindex] => 35
    [level] => 1
    [quality] => 4
    [inventory] => 77
    [quantity] => 1
    [rarity] => 2
    [attributes] => Array
        (
            [0] => Array
                (
                    [defindex] => 6
                    [value] => 1077936128
                    [float_value] => 3
                )

            [1] => Array
                (
                    [defindex] => 7
                    [value] => 1141712676
                    [float_value] => 564.61157226562
                )

            [2] => Array
                (
                    [defindex] => 8
                    [value] => 1031160533
                    [float_value] => 0.060122329741716
                )

            [3] => Array
                (
                    [defindex] => 147
                    [value] => models/weapons/stattrack.mdl
                )

        )

)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top