question

Ankur Ranpariya avatar image
Ankur Ranpariya asked

Simple Json is throwing error for Local Debug JSON file for Azure

Hi PlayFab Team,

I am facing issue for Simple Json DeserializeObject, when I am trying to Deserialize below given JSON string.

{
    "LocalApiServer": "http://localhost:7071/api/"
}

or

{"LocalApiServer":"http://localhost:7071/api/"}

this JSON data is stored in playfab.local.settings.json file for Local testing of Azure Function with VS Code and unity.

While PlayFab SDK tries to Deserialize the string, it is throwing SerializationException: Invalid JSON string` in SimpleJson.cs of PlayFab SDK.

Dev Settings:

- Unity: 2019.1.4f1

- PlayFab SDK: 2.83.200330

- OS: Windows 10

CloudScript
5 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.

Sarah Zhang avatar image Sarah Zhang commented ·

Could you please tell us which specific method are you using to deserialize it, could you provide the sample code?

0 Likes 0 ·
Ankur Ranpariya avatar image Ankur Ranpariya Sarah Zhang commented ·

Hi Sarah,

Thanks for the reply, I am trying to use ExecuteFunction using PlayFabCloudScriptAPI Class.

This is the Code that we are using for Execute Azure Function.

var request = new PlayFab.CloudScriptModels.ExecuteFunctionRequest()
{
    Entity = new PlayFab.CloudScriptModels.EntityKey()
        {
            Id = PlayFabSettings.staticPlayer.EntityId,
                Type = PlayFabSettings.staticPlayer.EntityType
        },
        FunctionName = "HelloWorld",
        FunctionParameter = new Dictionary<string, string>()
        { { "name", "Ankur" }, { "role", "Dev" }
        },
        GeneratePlayStreamEvent = true
};
PlayFabCloudScriptAPI.ExecuteFunction(request, (result) =>
{
    Debug.LogFormat("Function Result: {0}", result.ToJson());
}, (error) =>
{
    Debug.LogFormat("Function Error: {0}", error.GenerateErrorReport());
});
0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Ankur Ranpariya commented ·

Could you please tell us how do you call Simple Json DeserializeObject to Deserialize {"LocalApiServer":"http://localhost:7071/api/"}, could you provide this part of code? Thanks.

0 Likes 0 ·
Show more comments
Sarah Zhang avatar image Sarah Zhang commented ·

I’m not sure why it causes SerializationException. But PlayFab API does not support to locally test the Azure function, you may need to define the custom POST request to on your own to do local testing of Azure function. The key point would be constructing the correct context to mock PlayFab operation. You can get the context using the following code in the Azure function.

dynamiccontext = JsonConvert.DeserializeObject(awaitreq.ReadAsStringAsync());

log.LogInformation($"Function execution's context: {context}");
0 Likes 0 ·

1 Answer

·
Ankur Ranpariya avatar image
Ankur Ranpariya answered

Hi Sarah,

1. Yes, PlayFab Support Local Azure Function testing, Please check this URL: https://github.com/PlayFab/PlayFab-Samples/tree/master/Samples/CSharp/AzureFunctions/TicTacToeFunctions

2. I found the issue and why it occures, the file with below content was saved with some different (UTF-8-BOM) encoding. Once I change encoding to UTF-8, it working fine. and I am able to test Azure function locally with VS Code

{
    "LocalApiServer": "http://localhost:7071/api/"

}
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.

Johan de Bruin avatar image Johan de Bruin commented ·

Got the same issue and solved it with a similar approach. In my case, I just recreated the playfab.local.settings.json using notepad..

The JSON plugin should probably warn about an incorrect encoding or something..

1 Like 1 ·
Sarah Zhang avatar image Sarah Zhang commented ·

So thanks for sharing. I will accept your solution as the answer.

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.