1

Using the Steam API found here api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/ I get a JSON string like the one below. As you can see, it contains an array of item objects. What I'd like to do is to turn this array into a Map where the defindex is the key and the value is the corresponding item object at point of deserialisation using GSON.

Is this possible or do I have to do that after it's created the objects and populated the array?

 "result": {
            "status": 1,
            "num_backpack_slots": 800,
            "items": [
                {
                    "id": 12222222,
                    "original_id": 333333333,
                    "defindex": 45,
                    "level": 10,
                    "quality": 3,
                    "inventory": 2147483922,
                    "quantity": 1,
                    "origin": 0,
                    "style": 0,
                    "attributes": [
                        {
                            //...
                    ]

                },
            {
                "id": 3332222222,
                "original_id": 554545465,
                "defindex": 116,
                "level": 10,
                "quality": 6,
                "inventory": 2147483865,
                "quantity": 1,
                "origin": 0,
                "equipped": [
                    {
                        "class": 6,
                        "slot": 7
                    },
                    {
                        "class": 8,
                        "slot": 7
                    }
                ]
                ,
                "style": 1,
                "attributes": [
                          //...
                ]

            },
            {
                "id": 4658518468,
                "original_id": 897545164648,
                "defindex": 130,
                "level": 5,
                "quality": 3,
                "inventory": 2147484134,
                "quantity": 1,
                "origin": 0,
                "attributes": [
                    {
                        //...
                ]

            }
     ]
  • I think you are looking for **GSON custom deserialization** Please check this simple tutorial on this subject: [here](https://futurestud.io/tutorials/gson-advanced-custom-deserialization-basics) And you can also reffer to this SO answer on how to create a GSON deserializer: https://stackoverflow.com/questions/6096940/how-do-i-write-a-custom-json-deserializer-for-gson – V. Sambor Feb 24 '20 at 23:38
  • Hey thanks, I managed to get it working as I wanted! – silly_face_ Mar 01 '20 at 22:01

0 Answers0