question

Richard McKinney avatar image
Richard McKinney asked

Unity PlayfabEventsApi.WriteEvents PayloadJson serialization incorrect

When I send a Json string in EventContents.PayloadJSON, which has already been serialized the way I want it, it gets double escaped by the SimpleJson serializer in SerializeString.

For instance, if I set EventContents.PayloadJSON to (formatting/naming adjusted for readability):

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; min-height: 14.0px}

"{

“levelId”:5,

“characterInteractions”:”{\”4\”,6}”,

“playerInteractions”:”{\”3\”,5}”,

"bid":"0.6.2"

}"

It will come out on the backend looking like this:

"PayloadJSON”:

”{\”levelId\”:5,

\”characterInteractions\”:\”{\\\”4\\\”: 6}\”,

\”playerInteractions\”:\”{\\\”3\\\”: 5}\”,

\"bid\":\"0.6.2\"}"

I'll probably first try changing the serializer to Json.Net since we're also using that elsewhere.

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 Richard, could you please provide some steps for us to reproduce this issue? It seems to me that SimpleJson serializer wasn't utilized anywhere in the whole process, I tried to reproduce it but had no luck.

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.

Richard McKinney avatar image Richard McKinney commented ·

Hi Citrus,

Sorry, I think this was my mistake after all. I'm doing local caching and batching of events to support offline play, and didn't catch the extra escaping creeping in from that serialisation pass. Should have made a simpler repro case before asking :)

The SimpleJson serializer was being called from MakeApiCall: Payload = Encoding.UTF8.GetBytes(serializer.SerializeObject(request)),

Thanks!

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Richard McKinney commented ·

Hi Richard,

I was using Unity SDK(2.71.190821), the serializer in MakeAPICall is PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer). Hence I thought SimpleJson serializer wasn't being called. But nevermind, I'm glad you figured it out:)

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.