question

joerg-miethe avatar image
joerg-miethe asked

How to acsses an item in javaScript

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

joerg-miethe avatar image joerg-miethe commented ·

sorry... to much beer after a day spending on this:

code:

var HerbiListRequest = { CustomId: CustomID, };

EmptyHerbiList = PlayFabClientSDK.GetUserInventory(HerbiListRequest);

EmptyHerbiList.then(function(EmptyHerbiList){

JavaHerbi = JSON.parse(EmptyHerbiList.item);

console.log(JavaHerbi);

}

in the console I can read every data I want :-)

but I can't acsess by code... :-)

seems the promise is a JS.Object with a Json inside...?

I've tried everything.

.Data

.data

.Item

.item

.Items

and so on...

but I can't reach the data

What should I do :-(( ?

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

Firstly, according to the API reference of the client API GetUserInventory. You do not need to add “CustomId” field in the request body. You can modify the line 1 to “var HerbiListRequest = {};”. Secondly, you need to navigate to “EmptyHerbiList.data.Inventory” to get the Inventory field in the response. Finally, the Inventory of GetUserInventoryResult is an array, so you can use array.forEach() method to get the items in it.

  var getUserInventoryRequest = {};
        inventoryList = PlayFabClientSDK.GetUserInventory(getUserInventoryRequest);
        inventoryList.then(function (inventoryList) {
            inventoryList.data.Inventory.forEach(item => console.log(item));
        });

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

joerg-miethe avatar image joerg-miethe commented ·

Thank You so much :-)

works on first try

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.