question

andrearossini avatar image
andrearossini asked

JSON Serialization

Hi,


We are working on an update for a game that is already published on Google Play and AppStore.

We are trying to integrate the newer version of all plugins we use.

With PlayFab there was no issues until we run into a problem with a different JSON serialization.

In the previous version of the game there will be this:

Dictionary<string, object> replay = new Dictionary<string, object>();

<..>

	Fill dictionary.

</..>

string serializedReplay = JsonConvert.SerializeObject(replayData);
return serializedReplay;

Now we have this:

Dictionary<string, object> replay = new Dictionary<string, object>();

<..>

	Fill dictionary.

</..>

string serializedReplay = PlayFab.Json.JsonWrapper.SerializeObject(replay);
return serializedReplay;

cause JsonConverter was deleted in new version.

The problem is that the returned string is a bit different in this two cases. Is it possible? Did you do change serialization method in this update?

The differences are about some special character like ' " ' or ' \ ' before strings.

Is there a method to obtain the same result? We need to do this because we have to keep the compatibility with previous version of the game that read replay with that format.

Thank you.

Best regards,

Andrea.

10 |1200

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

brendan avatar image
brendan answered

Assuming you mean the Unity SDK, we changed to use SimpleJSON back in 2016: https://api.playfab.com/releaseNotes/p4#160222. What SDK version was the title originally shipped on? If you'd like to use the previous serializer (JSON.net), there are instructions on doing that in the SDK upgrade guide, here: https://github.com/PlayFab/UnitySDK/blob/66101881c49c5bda8667f89684c1f48a32de66be/V2UPGRADE.md (along with the details of the serializer changes).

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.

andrearossini avatar image andrearossini commented ·

original.txt

current.txt

I don't know which version they were using, cause the shipped version of this game wasn't developed by us.

I've attached to this post the original json serialized ("original.txt"). I've also attached mine serialized JSON (created with the current version of SDK).

I need to recreate the same structure to be sure that everything will be read correctly in older game version.

I've read your post on serialization update.

The older game was using JsonConvert.SerializeObject(...).

Now using JsonWrapper or SimpleJSON we have the same result, but different from the one obtained with JsonConvert.

How can we handle this? Thank you.

Best regards,
Andrea.

0 Likes 0 ·
original.txt (2.0 KiB)
current.txt (40.6 KiB)
brendan avatar image brendan andrearossini commented ·

In "original", what you have is an encoded string which for some reason contains a massive amount of whitespace (which should be removed, to save on bandwidth, but we can address that once we determine how you should proceed), while in "current", you have a key named "ticks" which contains an array of object arrays, where each object has been stringified. Given the specifics of the calls you were making, I'd recommend using the JSON.net serializer, since that should match what you were using at the time of the original code. I'll also discuss this with the tools team once we're all in the office, to see if they can provide additional recommendations.

0 Likes 0 ·
Ricardo Silva avatar image
Ricardo Silva answered

We need a new tutorial for Serialization/Deserialization. Thank you.

10 |1200

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

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.