question

mkolinichenko avatar image
mkolinichenko asked

SerializationException: Invalid JSON string in Unity

Hello, community!

I hope this is the right place for questions. I'm using sample code provided on this page - https://api.playfab.com/docs/getting-started-with-playfab and I'm getting this error:

SerializationException: Invalid JSON string
PlayFab.Json.PlayFabSimpleJson.DeserializeObject (System.String json) (at Assets/Plugins/PlayFabSdk/Shared/Internal/SimpleJson.cs:568)
PlayFab.Json.PlayFabSimpleJson.DeserializeObject (System.String json, System.Type type, IJsonSerializerStrategy jsonSerializerStrategy) (at Assets/Plugins/PlayFabSdk/Shared/Internal/SimpleJson.cs:600)
PlayFab.Json.PlayFabSimpleJson.DeserializeObject[HttpResponseObject] (System.String json, IJsonSerializerStrategy jsonSerializerStrategy) (at Assets/Plugins/PlayFabSdk/Shared/Internal/SimpleJson.cs:608)
PlayFab.Json.SimpleJsonInstance.DeserializeObject[HttpResponseObject] (System.String json) (at Assets/Plugins/PlayFabSdk/Shared/Internal/ISerializer.cs:136)
PlayFab.Json.JsonWrapper.DeserializeObject[HttpResponseObject] (System.String json) (at Assets/Plugins/PlayFabSdk/Shared/Internal/ISerializer.cs:34)
PlayFab.Internal.PlayFabWww+<MakeApiCall>c__AnonStorey12.<>m__F (System.String response) (at Assets/Plugins/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:75)
UnityEngine.Debug:LogException(Exception)
PlayFab.Internal.<MakeApiCall>c__AnonStorey12:<>m__F(String) (at Assets/Plugins/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:145)
PlayFab.Internal.<Post>c__Iterator7:MoveNext() (at Assets/Plugins/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:200)

The string itself is � if it helps.

I'm able to see login events in Playstream Debugger in Dashboard.

Thanks for future help!

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

We have a similar discussion, specific to the catalog in that case, in this thread: https://community.playfab.com/questions/8408/getcatalogitems-on-ios-devices.html. In short, non-alphanumberics haven't been tested with our SDK, so it's entirely possible they won't work with the SimpleJson serializer. For this case, what's the specific API call you're making when you see this error? Can you get us a Wireshark or Netmon capture that shows the details of the packets?

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

mkolinichenko avatar image mkolinichenko commented ·

And here is the capture from Microsoft Network Monitor - https://dl.dropboxusercontent.com/u/28316544/unity.cap

0 Likes 0 ·
mkolinichenko avatar image mkolinichenko commented ·

Looks like I got this. I've added Debug.Log(www.responseHeaders) and saw that response headers contain this:

..., Content-Encoding, ..., CONTENT-ENCODING=gzip, ...

Then I looked at line 176 @ PlayFabWWW.cs:

if (www.responseHeaders.TryGetValue("Content-Encoding", out encoding) && encoding.ToLower() == "gzip")

and changed it to this:

if (www.responseHeaders.TryGetValue("CONTENT-ENCODING", out encoding) && encoding.ToLower() == "gzip")

and it worked!

So... does anybody use this sdk except me?

0 Likes 0 ·
mkolinichenko avatar image mkolinichenko commented ·

I'm just starting, so I'm using exactly the code from "getting started" link. I guess it has only one call - LoginWithCustomID. CreateAccount is set to true, TitleId is 3 numbers + 1 latin letter, custom id received from unity. I've tried to replace SystemInfo.deviceUniqueIdentifier with "123" string - the error is the same.

As for Wireshark I'm afraid I'll need some help on this. How can I get the specific packets?

0 Likes 0 ·
brendan avatar image brendan mkolinichenko commented ·

Actually, capitalization that header element should be irrelevant. But can you turn off compression for now? It looks like you may be hitting some corner cases due to that. We'll have our tools team dig into compression on iOS.

0 Likes 0 ·
mkolinichenko avatar image mkolinichenko brendan commented ·

Looks like it is relevant. I use unity editor and android. And it's the response, which comes with compression, how can I turn this off?

0 Likes 0 ·
Show more comments
esk avatar image
esk answered

The solution I finally figured out is to set "Accept-Encoding" to "identity" in the extraHeaders argument when calling ExecuteFunction. There seems to be some problem with the gzip encoding, hopefully the PlayFab team will figure it out as this seems to be an issue quite a few people are having. I was personally having this issue when developing locally, but now I seem to have it when using the cloud hosted Azure Functions directly too, and I don't know why!

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.