Open colinmacleod opened 4 years ago
Hmm, my post seems to have swallowed the generics. The first part should read:
My first attempt to implement uses:
JsonSerializer.Deserialize<dynamic>(myJsonString)
and
JsonSerializer.ToJsonString<dynamic>(myDynamic)
@neuecc - could you please send a brief reply? if this is possible, I'd love you use Utf8Json
How is this? https://github.com/neuecc/Utf8Json/issues/52
Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
new[] { PrimitiveObjectFormatter.Default },
new[] { Utf8Json.Resolvers.GeneratedResolver.Instance, Utf8Json.Resolvers.BuiltinResolver.Instance });
Initialization to use Dictionary conversion
Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
new[] { Utf8Json.Formatters.PrimitiveObjectFormatter.Default },
new[] {
Utf8Json.Resolvers.GeneratedResolver.Instance,
Utf8Json.Resolvers.BuiltinResolver.Instance,
Utf8Json.Resolvers.DynamicGenericResolver.Instance
});
Unitypackage 1.3.7.1 doesn't contain this commit to fix a bug. https://github.com/neuecc/Utf8Json/commit/7f7d6e30b65e56e250baa49f5becba64730e5227
I have an implementation that works fine on Unity Editor (macOS) but I am having trouble getting the same code to work on iOS.
The code does not use any class conversion at all - I’m only using dynamics or Dictionary conversion.
My first attempt to implement uses JsonSerializer.Deserialize(myJsonString) and JsonSerializer.ToJsonString(myDynamic).
When I deploy to iOS I get the following error:
This happens on initialization at this point in an Awake method, the code is just the boilerplate copied from the docs:
If I remove that code from the Awake method, it fails on this line:
And this is the error message:
Then I noticed this comment on the Unity documentation page https://docs.unity3d.com/Manual/iphone-unsupported.html:
So, I reimplemented my code replacing every dynamic with Dictionary<string, object>. My code for the above line now looked like:
var json = JsonSerializer.Deserialize<Dictionary<string, object>>(resourceFile.text);
But the results were the same. The code did not work on iOS regardless. Again, it does work in Unity Editor with or without the startup code in Awake.
I tried running Utf8Json.UniversalCodeGenerator with various input files, but it didn’t seem to make any difference.
Not sure whether this is relevant, I am using Unity assembly definition files, and Utf8Json is in its own assembly with that name.
What am I missing?
@neuecc - I am sorry to raise this as an issue ticket. This is probably covered by the docs, but I could not work it out. I did spend several hours trying to get it to work and googling for a solution, before posting it up here.
I wasn't sure of the best way to contact you and I thought this might be useful to someone else!