Hi all,
I am recently working on a new PlayFabCloudScriptFunction with Azure Functions. I have encountered an issue with Json Deserialization of my request. On the Unity client side, I have some thing like this:
PlayFabCloudScriptAPI.ExecuteFunction( GetRequest(CloudScriptConstants.CompleteSingleplayerGameFunctionName, new CompleteSingleplayerGameRequest(gameState)), GetCallback(resultCallback, errorCallback), error => errorCallback.Invoke());
where gameState is like this:
public class GameState { public Dictionary<int, int> playerRelics { get; private set; } // ... Other fields are removed and they are probably not an issue. }
On Azure Functions side, I did this (this pattern worked fine for all other types including nested object and lists):
var context = JsonConvert.DeserializeObject<FunctionExecutionContext<CompleteSingleplayerGameRequest>>( await req.ReadAsStringAsync());
and it fails because the playerRelics is like this in json:
"playerRelics": [ { "Key": 29, "Value": 1 }, { "Key": 9, "Value": 1 } ],
I think JsonConvert is looking for this:
"playerRelics": { "29: 1, "9":1 },
The issue might caused by the dictionary key is an int but not a string. But I doubt changing it to string will change the serialization format. The Key, Value seems to be a certain serialization format that is coming with PlayFab in Unity.
BTW I have Odin Inspecter & Serializer installed. Will this be the cause?
I tried PlayFabSimpleJson on Azure side but it will throw this:
Object reference not set to an instance of an object.
Thanks!
Kevin
,Hi all,
Recently I have created a PlayFab Execute Function with request containing objects like this:
public class GameState { public Dictionary<int, int> playerRelics { get; private set; } //... Removed other fields }
Usually what I do it at Unity client side, I call
PlayFabCloudScriptAPI.ExecuteFunction( GetRequest(CloudScriptConstants.CompleteSingleplayerGameFunctionName, new CompleteSingleplayerGameRequest(gameState)), GetCallback(resultCallback, errorCallback), error => errorCallback.Invoke());
Then on the Azure Function side I do:
var context = JsonConvert.DeserializeObject<FunctionExecutionContext<CompleteSingleplayerGameRequest>>(await req.ReadAsStringAsync());
This pattern worked fine until I have put that GameState object into the request. And the issue is with the dictionary. Somehow, unity client side serialization converted it into this:
"playerRelics": [ { "Key": 29, "Value": 1 }, { "Key": 9, "Value": 1 } ],
Which is rather questionable as I thought Dictionary should be converted into this:
"playerRelics": { "29":1, "9":1 },
I am not sure if it is caused by the dictionary key is an int instead of a string so it cannot automatically serialize it as I thought it would.
Anyway, I tried to use PlayFabSimpleJson.DeserializeObject<xxx> but it will get this: Object reference not set to an instance of an object.
Please help me take a look. Thanks!