question

oskar avatar image
oskar asked

Excessive parsing when dealing with Objects fetched from PlayFab

When fetching player entity data from backend I run into the situation where I have to parse the data multiple times to load it into my client side value objects. Feels like there should exist a more efficient way to deal with this?

response here is a GetObjectsResponse from PlayFabDataApi.GetObjects

JsonObject jsonResult = (JsonObject)response.Objects["PlayerObject"].DataObject;
// Debug.Log(jsonResult.ToString());
PlayerObject obj = JsonUtility.FromJson<PlayerObject>(jsonResult.ToString());

as you can see there's a ToString performed on the JsonObject before parsing it with JsonUtility to my own Type. And I can only assume there is some parsing inside the PlayFab sdk as well of whatever comes over the wire from backend. This seems excessive to me. Is there a way to slim this down?

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

·
Citrus Yan avatar image
Citrus Yan answered

Hi @oskar,

The response.Objects["PlayerObject"].DataObject is already parsed as an Un-escaped JSON object by the PlayFab SDK, you can check the code in here. Therefore, there is no need to cast it to the JsonObject in the first line of your code, you can parse it to your own type simply by doing this:

PlayerObject obj =
JsonUtility.FromJson<PlayerObject>(response.Objects["PlayerObject"].DataObject.ToString());
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.

oskar avatar image oskar commented ·

Ok, so it's not quite as bad as it seemed. That's good :)

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.