question

entelicon avatar image
entelicon asked

CloudScript return issue

CloudCode

var allRandomComponents = server.GetUserInternalData({
        PlayFabId : currentPlayerId,
    })

    return allRandomComponents.Data;


Unity/C#
UserDataRecord[] test = (UserDataRecord[])success.FunctionResult;


            foreach (UserDataRecord item in test)
            {
                Debug.Log(item.Value);
            }


I'm trying to return the data from the CloudCode and parse it on the client.
CloudScript
10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

The FunctionResult is a JSON object (https://api.playfab.com/documentation/client/method/ExecuteCloudScript), not an array of UserDataRecord. What I would recommend is casting it to an IEnumerable, so that you can then iterate through the elements in your foreach.

2 comments
10 |1200

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

entelicon avatar image entelicon commented ·

IEnumerable test = (IEnumerable)success.FunctionResult;


            foreach (IEnumerable item in test)
            {
                Debug.Log(item);
            }
Not sure what you mean but I did what you said. Not working
0 Likes 0 ·
brendan avatar image brendan entelicon commented ·

Tell you what - go with this:

List<UserDataRecord> dataItems = JsonWrapper.DeserializeObject<List<UserDataRecord>>(result.FunctionResult.ToString());

That should get you what you need.

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.