Sep 24, 2012 at 1:12 PM
Edited Sep 24, 2012 at 1:14 PM

First and foremost thanks for your work on this api, its really great, but since I'm very new at working with Dynamic objects I may need some help.I'm trying hard to iterate on the items of a Hero Profile, but neither for or foreach works...


for (Int32 Index = 0; Index >= HeroProfile.items.dictionary.Count - 1; Index++)
for (Int32 Index = 0; Index >= HeroProfile.items.Count - 1; Index++)
for (Int32 Index = 0; Index >= HeroProfile.items.Count() - 1; Index++)

Does not Work...

Tried with foreach:

foreach (var Item in HeroProfile.dictionary[8])
foreach (var Item in HeroProfile.items)

doesn´t work as well...

Sep 24, 2012 at 5:39 PM
Edited Sep 24, 2012 at 5:48 PM


I have looked into the problem you are having. You are unable to iterate through HeroProfile.items because items is not an actual array (list). If you look at the JSON returned from Blizzard's API for items, items is just an object that holds other objects (head, torso, ect..):

(Continues at bottom)

"items": {
        "head": {
            "name": "Wild Casque of Invasion",
            "icon": "helm_104",
            "displayColor": "blue",
            "tooltipParams": "item-data/CPvK9pADEgcIBBU69U5dHTIL5KIdAn-SATAJOPUDQABIFVAIYPUD"
        "torso": {
            "name": "Covenant Invasion",
            "icon": "chestarmor_105",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CJrCw64IEgcIBBXtHRlgHQJ_kgEd6SuJOh3Y7Sq9HZMCY-oiCwgBFWdCAwAYDiAUMAk4qAVAAEgNUAxgqAVqJQoMCAAQ8--hp4CAgOAwEhUIqNWDxQMSBwgEFfSe2KswCTgAQAFqJQoMCAAQifChp4CAgOAwEhUIvbPojwkSBwgEFfSe2KswCTgAQAFqJQoMCAAQp_Chp4CAgOAwEhUI17rWjQwSBwgEFfSe2KswCTgAQAE"
        "feet": {
            "name": "Relentless Battle Greaves of Invasion",
            "icon": "boots_105",
            "displayColor": "blue",
            "tooltipParams": "item-data/CILd8t4NEgcIBBVcQZt_HdM9BzUdQzTvhjAJOIYEQABIDVAIYIYE"
        "hands": {
            "name": "Cruel Gage",
            "icon": "gloves_103",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CMzrzgESBwgEFYNXkqQd9ORSKh3gzHZQHRCRU2gdvdK3LR0Cf5IBIgsIABW6RAMAGBogGDAJONgDQABIDVAOYNgD"
        "shoulders": {
            "name": "Champion Reprisal",
            "icon": "shoulders_104",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CIuLmwMSBwgEFY30yBUd0cIitx0axFF0HeE5hwIdvlvoSCILCAEVu0QDABgUICYwCTiDBUAASBJQDGCDBQ"
        "legs": {
            "name": "Battle Cinder",
            "icon": "pants_102",
            "displayColor": "yellow",
        "bracers": {
            "name": "Protection Mettle",
            "icon": "bracers_103",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CIW466IFEgcIBBWVKMrLHQJ_kgEdD9xxfB2crKCYHRKHPlYdSFJ1-h1DYFFAIgsIARVvQgMAGAQgADAJOOEDQABQEGDhAw"
        "mainHand": {
            "name": "Destruction Wisp",
            "icon": "sword_2h_201",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CMGq1KMEEgcIBBX6_S7yHZtssxQdS2NPMB2o7995HWPY6agiCwgBFXdCAwAYACAUMAk4hQRAAFAMYIUE"
        "offHand": null,
        "waist": {
            "name": "Scale Envy",
            "icon": "belt_105",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CMXv_fcHEgcIBBV8o0LUHUoyxxwd3WH9HR0fhz5WHUM074YiCwgBFXVCAwAYDiASMAk4wQNAAFAMYMED"
        "rightFinger": {
            "name": "Empty Band",
            "icon": "ring_09",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CMn4h5MJEgcIBBX4VF1EHRhNvCodulvoSB2FvzSKHUDxmysiCwgAFcv-AQAYDCAGMAk47QJAAFAMYO0CaiUKDAgAELTa1JqAgIDgIBIVCJvB4cEOEgcIBBVF9YtfMAk4AEAB"
        "leftFinger": {
            "name": "Gambler's Loop",
            "icon": "ring_10",
            "displayColor": "yellow",
            "tooltipParams": "item-data/CNT-vN0DEgcIBBUQVV1EHYutUmgdRH0C5R0-vYo1HRjTLBAdjrDM0B0WpNPYIgsIABW2_gEAGCQgCDAJOKwDQABQEGCsA2okCgwIABCk2tSagICA4CASFAjysbA9EgcIBBVF9YtfMAk4AEAB"
        "neck": {
            "name": "Nobility Aim",
            "icon": "amulet07",
            "displayColor": "yellow",
            "tooltipParams": "item-data/COCVqNAHEgcIBBWPxURkHSUlWp4dO7LM0B29_O7IHTKHYggiCwgBFcZEAwAYGiAkMAk4kANAAFAMYJADaiUKDAgAEKimv5GAgICgAxIVCOfkurINEgcIBBVG9YtfMAk4AEAB"

So, because items are not returned as a list, you must access them by their names (identifiers), like so:

D3API api = new D3API(HostName.en_US);
int heroid = api.getCareerProfile("Battletag#0000").heroes[0].id;
var hero = api.getHeroProfile("Battletag#0000", heroid);

var head = hero.items.head;
var torso = hero.items.torso;
If you are having trouble with navigating the dynamic object, I recommend that you download the api test tools and play around with that.
Sep 24, 2012 at 6:12 PM

Hi, thanks for the reply... That´s what I ended up doing, It was not the way I wanted to do it, but thats what we have.

The problem kept on goind for the items' properties. I tried to iterate on its raw properties and got the same error, probably for the sane reasons, and this just kill the whole idea I had for my tool, which was making an HUGE Item database for D3 Items.

Thanks a lot for the support, and great work!

Sep 25, 2012 at 12:03 AM

You could write a method to construct the item array for you:

public dynamic[] getItems(dynamic heroProfile)
            dynamic[] items = new dynamic[12];
            items[0] = heroProfile.items.head;
            items[1] = heroProfile.items.torso;
            items[2] = heroProfile.items.feet;
            items[3] = heroProfile.items.hands;
            items[4] = heroProfile.items.shoulders;
            items[5] = heroProfile.items.legs;
            items[6] = heroProfile.items.bracers;
            items[7] = heroProfile.items.mainHand;
            items[8] = heroProfile.items.offHand;
            items[9] = heroProfile.items.rightFinger;
            items[10] = heroProfile.items.leftFinger;
            items[11] = heroProfile.items.neck;
            return items;
I know it's messy and not elegant, but, like you said: it's what we have.

Sep 25, 2012 at 2:28 AM
Edited Sep 25, 2012 at 2:30 AM

Man, I can´t thank you enough for the replies so far, but I went in other direction. I gave up on the D3api and did it using JSON.net like so:


var HeroDetails = _download_serialized_json_data<dynamic>(HeroDetailsUrl);
                    foreach (var Item in HeroDetails["items"])

                        var ItemData = JsonConvert.DeserializeObject<dynamic>(Convert.ToString(Item.Value));

 and it worked like I intended.

as I result I could save the item, look for its details and save them as well onto another table.

Sep 25, 2012 at 2:33 AM

and since I don´t know which Item has what stats I´ve used the dynamic idea (something very new to me) and the info is saved like so:

1 101 Sockets 1 1 1

2 101 Durability_Cur 396 396 1

3 101 Armor_Item 335.5 335.5 1

4 101 Durability_Max 396 396 1

5 101 Dexterity_Item 71 71 1

6 101 Vitality_Item 70 70 1

7 101 Resource_Regen_Per_Second#Spirit 2.18333333333333 2.18333333333333 1

8 101 Resistance#Arcane 28 28 1

That was really what I had in mind, an Item database, to what end I don´t know yet... :)