question

digitalaec avatar image
digitalaec asked

CloudScript GetPlayerCombinedInfo, little problem.

Hi, i can't get player data on cloud script. Thanks for help.

PlayerCombinedInfo part here.

var GetPlayerCombinedInfoRequest = 
		{
			"PlayFabId": currentPlayerId,
			"InfoRequestParameters" : 
			{
    			"GetUserAccountInfo": true,
    			"GetUserInventory": true,
   				"GetUserVirtualCurrency": true,
   				"GetUserData": false,
    			"GetUserReadOnlyData": true,
    			"GetCharacterInventories": false,
   				"GetCharacterList": false,
    			"GetTitleData": false,
    			"GetPlayerStatistics": true
			}
		};
		var GetPlayerCombinedInfoResult = server.GetPlayerCombinedInfo(GetPlayerCombinedInfoRequest);
		return JSON.stringify(GetPlayerCombinedInfoResult.InfoResultPayload);

ExecuteCloudScript on Client,

ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest

                {

                    FunctionName = GlobalStrings.CloudFunction_GetInitData

                };

PlayFabClientAPI.ExecuteCloudScript(request, GetInitData_Success, ErrorControl);

Result on Client,

GetPlayerCombinedInfoResultPayload playerData = new GetPlayerCombinedInfoResultPayload ();



playerData = PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(result.FunctionResult.ToString());

Debug.Log(playerData.AccountInfo.PlayFabId);

I know, this my fault but where do i make mistakes? Deserialize is wrong ? Please show me the correct way, thanks.

There is log,

InvalidCastException: Value is not a convertible object: System.String to System.Nullable`1[[PlayFab.ClientModels.UserOrigination, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Convert.cs:2941)
System.String.System.IConvertible.ToType (System.Type targetType, IFormatProvider provider) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/String.cs:2420)
System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Convert.cs:2937)
System.Convert.ChangeType (System.Object value, System.Type conversionType, IFormatProvider provider) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Convert.cs:2511)
PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) (at Assets/PlayFabSdk/Shared/Internal/SimpleJson.cs:1416)
PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) (at Assets/PlayFabSdk/Shared/Internal/SimpleJson.cs:1482)
PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) (at Assets/PlayFabSdk/Shared/Internal/SimpleJson.cs:1482)
PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) (at Assets/PlayFabSdk/Shared/Internal/SimpleJson.cs:1482)
PlayFab.Json.PlayFabSimpleJson.DeserializeObject (System.String json, System.Type type, IJsonSerializerStrategy jsonSerializerStrategy) (at Assets/PlayFabSdk/Shared/Internal/SimpleJson.cs:603)
PlayFab.Json.PlayFabSimpleJson.DeserializeObject[GetPlayerCombinedInfoResultPayload] (System.String json) (at Assets/PlayFabSdk/Shared/Internal/SimpleJson.cs:618)
PlayFab.Json.SimpleJsonInstance.DeserializeObject[GetPlayerCombinedInfoResultPayload] (System.String json) (at Assets/PlayFabSdk/Shared/Internal/ISerializer.cs:61)
PlayFab.Json.JsonWrapper.DeserializeObject[GetPlayerCombinedInfoResultPayload] (System.String json) (at Assets/PlayFabSdk/Shared/Internal/ISerializer.cs:33)
TriflesGames.GeniusGame.DataManager.GetInitData_Success (PlayFab.ClientModels.ExecuteCloudScriptResult result) (at Assets/#TriflesGames#/Scripts/Managers/Playfab/Data/DataManager.cs:188)
PlayFab.Internal.PlayFabHttp+<MakeApiCall>c__AnonStorey0`1[PlayFab.ClientModels.ExecuteCloudScriptResult].<>m__1 () (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:170)
PlayFab.Internal.PlayFabWww+<MakeApiCall>c__AnonStorey1.<>m__0 (System.String response) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:126)
UnityEngine.Debug:LogException(Exception)
PlayFab.Internal.<MakeApiCall>c__AnonStorey1:<>m__0(String) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:130)
PlayFab.Internal.<Post>c__Iterator0:MoveNext() (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:200)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
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.

Joshua Strunk avatar image Joshua Strunk commented ·

I would try logging or inspecting what the value of result.FunctionResult.ToString() is. This might help find the funkiness going on that the serializer can't resolve.

1 Like 1 ·
1807605288 avatar image 1807605288 ♦ commented ·

My first suggestion is to take your result json:

result.FunctionResult.ToString()

And print it. Copy it into Json lint, and see if it's valid json.

0 Likes 0 ·
1807605288 avatar image
1807605288 answered

I have discovered that there are some obscure paths through the JsonWrapper, where our customizations for SimpleJson (IE handling nullables, enums, and timestamps properly) are not applied.

This issue should be fixed in the next patch.

You can fix this issue immediately by changing this line:

playerData =PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(result.FunctionResult.ToString());

to this line:

playerData =PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(result.FunctionResult.ToString(), PlayFabUtil.ApiSerializerStrategy);

Please note that I'm moving ApiSerializerStrategy out of PlayFabUtil with the fix, and so, you'll need to remove it after the next patch.

10 |1200

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

Joshua Strunk avatar image
Joshua Strunk answered

TL;DR change the return statement in your Cloud Script handler to

return GetPlayerCombinedInfoResult.InfoResultPayload;

---

Ah I think I got it after much looking up and down the problem here is

return JSON.stringify(GetPlayerCombinedInfoResult.InfoResultPayload);

combined with

result.FunctionResult.ToString()

I think.

Now what ends up happening is your FunctionResult is just actually a single Value of type string. Single value objects passed back have been known to cause trouble in the past though should be resolved. See here for more information on that. I suspect some funkiness is going on between returning a literal string value, the SDK deserializing it into a JSONObject, and you trying to get the literal string value you passed down by calling ToString().

Changing your return statement from you Cloud Script handler to just return the object and not a serialized version of it could solve the issue.

10 |1200

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

digitalaec avatar image
digitalaec answered

Update: Its working on my custom class.

Class,

public class PlayerData

{

    public Account_Info AccountInfo { get; set; }

}

public class Account_Info

{

    public string PlayFabId { get; set; }

}

Script,

playerData = PlayFab.Json.JsonWrapper.DeserializeObject<PlayerData>(result.FunctionResult.ToString());

Debug.Log(playerData.AccountInfo.PlayFabId);

Its working, i get PlayFabId.

Why not working on "GetPlayerCombinedInfoResultPayload" ?

My question is still open, thanks.

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.

Joshua Strunk avatar image Joshua Strunk commented ·

Did you try the proposed fix?

If so are you getting the same stacktrace or a different one?

Did you try logging the string you are attempting to deserialize?

If so can you post what the string is or at least redacted version of it?

0 Likes 0 ·
digitalaec avatar image digitalaec Joshua Strunk commented ·

Cloudscript is fine, its working and i get data. But when i try deserialize i get error.

0 Likes 0 ·
digitalaec avatar image
digitalaec answered
Sorry for delay. I am trying your answers but my problem not solved. Thanks for time.

.

.

.

CloudScript,

var GetPlayerCombinedInfoRequest = 
		{
			"PlayFabId": currentPlayerId,
			"InfoRequestParameters" : 
			{
    			"GetUserAccountInfo": true,
    			"GetUserInventory": true,
   				"GetUserVirtualCurrency": true,
   				"GetUserData": false,
    			"GetUserReadOnlyData": true,
    			"GetCharacterInventories": false,
   				"GetCharacterList": false,
    			"GetTitleData": false,
    			"GetPlayerStatistics": true
			}
		};
		var GetPlayerCombinedInfoResult = server.GetPlayerCombinedInfo(GetPlayerCombinedInfoRequest);
		return GetPlayerCombinedInfoResult.InfoResultPayload;

Script,

Debug.Log(result.FunctionResult);

Log,

{"AccountInfo":{"PlayFabId":"E8A95432D1B5E2AF","Created":"2016-12-10T00:11:29.692Z","TitleInfo":{"DisplayName":"ABCC","Origination":"CustomId","Created":"2016-12-10T00:11:29.712Z","LastLogin":"2017-01-08T13:46:36.318Z","FirstLogin":"2016-12-10T00:11:29.712Z","isBanned":false},"PrivateInfo":{},"CustomIdInfo":{"CustomId":"272538DC-0C59-5837-8E90-C29CF2C488D8"}},"UserInventory":[],"UserVirtualCurrency":{"DB":2,"DM":0,"GD":18,"HT":0},"UserVirtualCurrencyRechargeTimes":{},"UserDataVersion":0,"UserReadOnlyData":{"DailyBonus":{"Value":"{\"DailyBonus\":1483968845703}","LastUpdated":...............etc.....

Script,

Debug.Log(PlayFab.Json.JsonWrapper.SerializeObject(result.FunctionResult.ToString()));  

Log,

{\"AccountInfo\":{\"PlayFabId\":\"E8A95432D1B5E2AF\",\"Created\":\"2016-12-10T00:11:29.692Z\",\"TitleInfo\":{\"DisplayName\":\"ABCC\",\"Origination\":\"CustomId\",\"Created\":\"2016-12-10T00:11:29.712Z\",\"LastLogin\":\"2017-01-08T13:46:36.318Z\",\"FirstLogin\":\"2016-12-10T00:11:29.712Z\",\"isBanned\":false},\"PrivateInfo\":{},\"CustomIdInfo\":{\"CustomId\":\"272538DC-0C59-5837-8E90-C29CF2C488D8\"}},\"UserInventory\":[],\"UserVirtualCurrency\":{\"DB\":2,\"DM\":0,\"GD\":18,\"HT\":0},\"UserVirtualCurrencyRechargeTimes\":{},\"UserDataVersion\":0,\"UserReadOnlyData\":{\"DailyBonus\":{\"Value\":\"{\\\"DailyBonus\\\":1483968845703}\",\"LastUpdated\":...............etc.....

Script,

 Debug.Log(PlayFab.Json.JsonWrapper.SerializeObject(result)); 

Log,

"PlayFab.ClientModels.ExecuteCloudScriptResult"

I return data, its working but my problem deserialize.

Script,

playerData = PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(PlayFab.Json.JsonWrapper.SerializeObject(result));

Result,

Don't give error but when i try get value,

Debug.Log(playerData.AccountInfo.PlayFabId);
.

.

.

NullReferenceException: Object reference not set to an instance of an object

Its null :/

Script,

playerData = PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(PlayFab.Json.JsonWrapper.SerializeObject(result.FunctionResult.ToString()));

Log,

InvalidCastException: Value is not a convertible object: System.String to PlayFab.ClientModels.GetPlayerCombinedInfoResultPayload
System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) (at

BUT


My custom Class,

public class PlayerData

{

    public Account_Info AccountInfo { get; set; }

    public Dictionary<string,int> UserVirtualCurrency { get; set; }

    public Dictionary <string,UserReadOnlyDataRecord> UserReadOnlyData { get; set; }

    public List<Statistic_Value> PlayerStatistics { get; set; }



}

public class Account_Info

{

    public string PlayFabId { get; set; }

    public Title_Info TitleInfo { get; set; }

    public Facebook_Info FacebookInfo { get; set; }

}

public class Title_Info

{

    public string  DisplayName { get; set; }

}



public class Facebook_Info

{

    public string FacebookId { get; set; }

    public string FullName { get; set; }

}



public class UserReadOnlyDataRecord

{

    public string Value { get; set; }

    public DateTime LastUpdated { get; set; }

}



public class Statistic_Value

{

    public string StatisticName { get; set; }

    public int Value { get; set; }

    public int Version { get; set; }

}

AND RESULT,

Debug.Log(playerData.AccountInfo.PlayFabId);

.

.

.


E8A95432D1B5E2AF

Deserialize,

playerData = PlayFab.Json.JsonWrapper.DeserializeObject<PlayerData>(result.FunctionResult.ToString());

Where is the problem ? Why not working on "GetPlayerCombinedInfoResultPayload" class?

I don't want create custom class like GetPlayerCombinedInfoResultPayload. Because its have. We don't need duplicate it, we need fix it. Thanks for time.

My question still open.

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.

Joshua Strunk avatar image Joshua Strunk commented ·

Still hard to draw any conclusions. It looks like either you made an error in copying it for your post or tried to deserialize the wrong values.

---

playerData =PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(PlayFab.Json.JsonWrapper.SerializeObject(result));

I believe here you are trying to serialize the ExecuteCloudScriptResult and then deserialize that into a GetPlayerCombinedInfoResultPayload. That will not work would need to change result to result.FunctionResult.

---

playerData =PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(PlayFab.Json.JsonWrapper.SerializeObject(result.FunctionResult.ToString()));

Here you have result.FunctionResult.ToString() this returns the JSON encoded string of FunctionResult. The problem is you then pass that string into SerializeObject() which will take that string and serialize it into a JSON encoded string of a string. You can actually see what this look like in your 2nd Log post.

change your deserialization line to just be

playerData = PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(result.FunctionResult.ToString());
0 Likes 0 ·
digitalaec avatar image
digitalaec answered

Yep look my question on yesterday. (line 1, post 1)

I tried this way but i got error.

GetPlayerCombinedInfoResultPayload playerData = new GetPlayerCombinedInfoResultPayload ();

playerData = PlayFab.Json.JsonWrapper.DeserializeObject<GetPlayerCombinedInfoResultPayload>(result.FunctionResult.ToString()); 

Debug.Log(playerData.AccountInfo.PlayFabId);

Log,

Look up for the log. Thanks.

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.

digitalaec avatar image digitalaec commented ·

I was writed look first post,

"Result on Client,"

0 Likes 0 ·
Joshua Strunk avatar image Joshua Strunk digitalaec commented ·

Yes, but your first post had another issue in that it appeared you were not passing down a JSON object. It looked like you were instead passing down the string encoded JSON object. I personally have no idea if that should work or what side effects it had.

I am sorry I was unable to help you. I can not spend the time/resources needed to reproduce your test case, here are some more things you can try.

  • Keep printing out as much info as you can, I would break every step of the string processing out and log it. Use a JSON validator online to confirm you have a valid JSON string. I use.
  • Try returning less of the GetPlayerCombinedInfoResultPayload object to see if a certain part of it is breaking the serializer.
  • You might also consider submitting a ticket to PlayFab if you feel strongly this is a bug on their end.
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.