Sign In Register

How can we help you today?

Start a new topic

Getting a value from a dynamic key name from a GSData

For reference, I'm using C# in Unity.


Here's the data I'm getting from a LogEventResponse: 

   

{
    "@class": ".LogEventResponse",
    "requestId": "636748002281314750_1",
    "scriptData": {
        "friendsList": {
            "5bbe70267_PLAYERID": {
                "displayName": "test0"
            }
        }
    }
}

 

I know I can use  

GSData friendsList = response.ScriptData.GetGSData("friendsList");

 to get the "friendsList" value as GSData, but how can I get the XXXX_PLAYERID without knowing the key name? Since that will be a player's PlayerID. 


Also, let's say that a user has multiple friends so the data looks like this: 

 

{
    "@class": ".LogEventResponse",
    "requestId": "636748002281314750_1",
    "scriptData": {
        "friendsList": {
            "PLAYER_ID_1": {
                "displayName": "test0"
            },
            "PLAYER_ID_2": {
                "displayName": "test1"
            },
            "PLAYER_ID_3": {
                "displayName": "test2"
            }
        }
    }
}

 How can I get a list/array of every item in "friendsList" then get the child displayName as a string?

1 Comment

Hi Brandon,


I assume this coming from our friends tutorial in our documentation. The way I would approach this is to change how the actual data is sent in script data by sending an array of friend objects instead of sending an object of objects as it is difficult to get the keys which are friends ids.


The changes I would make to the tutorial to make it easier is the shown in the screen shot below.

Then in Unity you can get the data easier by iterating through the friendArray and pulling out the data that you need.

Regards,

Garreth.

Login to post a comment