After a few customer mails, I decide to open this thread for support.
BTW, the original Json.NET might not be suitable for iOS and WebGL because it uses System.Reflection.Emit.
Or you may need to download its source code to modify…
Big thumbs for sharing this! Simple yet useful alternative to the overpriced Json.Net packages in the Asset Store. When the core project is free, so should be the extensions/wrappers.
AFAIK, the official Newtonsoft.Json.dll provided by JSON.NET doesn’t support iOS for now.
But you could download it’s source code and remove the relatived code, and it’ll work.
Or there’s others who compiled the dll for Unity.
Note, it may be better to remove the old version before you update.
Since the Json.NET core dll is replaced.
Or you may use your preferred one and ignore the included.
I have to say, I’m so excited when I found the “Json.NET for Unity” becomes free!
I even thought that’s the time to deprecate this package.
Then I found it doesn’t handle Dictionary as I need.
Since I still need these converters, I try to deal with the cross platform problem.
According to @Bodkin 's help, I tried the Json.Net.Unity3D, on Windows, WebGL, Android.
(I have no iDevice… Oops!)
Then I decide to directly use it instead of including his helper… LOL
Wish we all enjoy it!
What is the reasoning behind the custom Dictionary converter? I actually ran into problems with it because its serialization and deserialization is incompatible with the functionality in Json.NET, and indeed with how I would expect JSON to be formatted. Is it designed to handle certain edge cases?
Hi. I’ve been using the converter in a project since Unity 2018.2, and it’s been working perfectly. Thanks for releasing it.
But my team has recently upgraded from 2018.3.5 to 2018.3.7 and suddenly everything’s broken.
In edit mode, I frequently get this exception appearing in the console:
System.TypeInitializationException: The type initializer for 'WanzyeeStudio.Json.JsonNetUtility' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
at (wrapper managed-to-native) System.Reflection.Assembly.GetTypes(System.Reflection.Assembly,bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <d7ac571ca2d04b2f981d0d886fa067cf>:0
at WanzyeeStudio.Json.JsonNetUtility+<>c.<FindConverterTypes>b__4_0 (System.Reflection.Assembly dll) [0x00000] in WanzyeeStudio\Scripts\Runtime\Concrete\Json\JsonNetUtility.cs:121
at System.Linq.Enumerable+SelectManySingleSelectorIterator`2[TSource,TResult].MoveNext () [0x00051] in <1b13ba6391c74847bbc3eddc86df7eee>:0
at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].ToArray () [0x00033] in <1b13ba6391c74847bbc3eddc86df7eee>:0
at System.Linq.Buffer`1[TElement]..ctor (System.Collections.Generic.IEnumerable`1[T] source) [0x0000a] in <1b13ba6391c74847bbc3eddc86df7eee>:0
at System.Linq.OrderedEnumerable`1[TElement].ToArray () [0x00000] in <1b13ba6391c74847bbc3eddc86df7eee>:0
at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <1b13ba6391c74847bbc3eddc86df7eee>:0
at WanzyeeStudio.Json.JsonNetUtility.FindConverterTypes () [0x00001] in WanzyeeStudio\Scripts\Runtime\Concrete\Json\JsonNetUtility.cs:119
at WanzyeeStudio.Json.JsonNetUtility.CreateConverters () [0x00001] in WanzyeeStudio\Scripts\Runtime\Concrete\Json\JsonNetUtility.cs:90
at WanzyeeStudio.Json.JsonNetUtility..cctor () [0x00000] in WanzyeeStudio\Scripts\Runtime\Concrete\Json\JsonNetUtility.cs:67
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[ ],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) [0x00032] in <d7ac571ca2d04b2f981d0d886fa067cf>:0
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()
And when running the project, I get a whole load of JsonSerializationExceptions when calling into Json.NET.
I’m hoping there’s a simple fix and would be grateful for any assistance.
Hi @neil_sublime ,
Very sorry for noticing your post so late.
I’ve tried this package in an empty Unity 2018.3.7 project, nothing happens.
The exception occurs at JsonNetUtility.cs, Line 121, “Assembly.GetTypes()”.
I guess there may be something in your project cause it, e.g., I’ve ever seen dynamic assemblies cause exceptions when I call some assembly methods.
The easiest way to fix it as below, and I’ll also patch it in this way in the next update.
Open “JsonNetUtility.cs” and find line 121 with the code snippet:
Thanks for the response. There was a problem with loading “accessibility” DLLs via reflection after Unity released 2018.3.7 to hotfix a remote execution flaw. That problem seems to have been fixed for the upcoming 2019.2 release.
After I realised that was the issue, I patched the code myself and it’s been working flawlessly again ever since. I would certainly appreciate getting an official fix however, and look forward to your update. Thanks again for your hard work in providing this library and maintaining it.
The Vector and Quaternion are now “JObject” type and the Enum is a string.
How can I have them deserialized properly to Vector3, Quaternion and Enum value ?
Thanks for your help !
Anthony
EDIT: I ended up converting JObject manually like this :
((JObject)field.Value).ToObject()