1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

JSON .NET for Unity

Discussion in 'Assets and Asset Store' started by Dustin-Horne, Sep 13, 2013.

  1. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    JSON .NET for Unity is now only $20!

    Serialization is integral to persisting data. This community has been extremely supportive of my asset and I wanted to return the favor by making sure it is affordable for everyone, so the price has been reduced on both FastSpring and the Asset Store.


    My new JSON .NET Asset has been released.

    With this release I bring JSON .NET to Unity 3.5+. While there have been other versions of JSON .NET floating around, they rely on older versions that will fail in Unity WebPlayer and will cause AOT errors in iOS. I've ported the JSON .NET library and removed those issues so it will now work on both WebPlayer and iOS. Find my asset here:

    Product Site
    On FastSpring
    On the Asset Store


    Highlights

    • Works in WebPlayer - Fixes KeyedCollection issues.
    • Works in iOS - No more AOT Errors from JSON .NET
    • Both JSON and BSON support have been ported
    • Retains most original JSON .NET namespaces
    • No DLL - This asset includes full source code

    The fourth bullet above is notably the most important. There are other assets in the Asset Store that implement JSON .NET and do so with a compiled DLL. You can remove that DLL and add this Asset as an instant drop-in replacement. The asset also includes full source code, no compiled DLL.

    I've also included a very rudimentary example scene. This includes a GameObject with an attached script that shows examples for serialization and deserialization for multiple scenarios (and gives examples of using both JSON and BSON).

    The implementation is nearly identical to that of the original Newtonsoft library. There are two primary differences. I've removed dependencies on libraries that are not supported by Unity (such as System.Data).

    UPDATE: Enums are now serialized to their Value by default. This is to stay consistent with the Newtonsoft implementation. You can serialize using a new EnumValueConverter which will serialize by value.

    Or leave any feedback you'd like here.

    Thanks!

    ~Dustin Horne
     
    Last edited: Jan 13, 2014
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
    Any chance that you provide dlls for this as well?
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Usually DLLs are provided and people are asking for source code.

    This particular asset is made to import directly into Unity and work. In order to maintain cross-platform compatibility I can't precompile it into a DLL. The framework differences are significant enough that the code requires precompiler directives to conditionally compile the correct version for different platforms. However, if you are only targeting iOS, you could download the asset, add it to a C# Class Library Project in Visual Studio and compile it yourself. You'd need to make sure you add the UNITY_IOS symbol in your build settings dialogue before compiling. You'd need to do this for UNITY_WEBPLAYER as well to target Unity WebPlayer. So you'd really need to build a separate assembly for the iOS, WebPlayer and desktop platforms. Otherwise, you can just import the asset as is and it will automatically compile to whatever your target platform is.

    If you get the asset you'll see conditionals like:
    Code (csharp):
    1.  
    2. #if UNITY_IOS
    3. ...code here
    4. #endif
    5.  
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
    I prefer it to get dlls and additionally to have the code within a Unity package. In 99% of the cases it is not necessary to see the source code and dlls reduces the compilation time a lot when the projects become heavier.
    Are there many of those platform specific code sections? Are they somehow centralized or distributed through the whole code?
     
    Ash-Blue likes this.
  6. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    The code base consists of somewhere around 192 files. There's a tremendous number of conditionals and they're pretty heavily distributed. They encompass a lot of platform specific code. Some of it is architectural differences and/or functionality that's not available for iOS and some of it is security related in the way binding and security flags are set for reflection.

    This is my first asset on the Asset Store. If you're aware of a way to include the DLLs without them being automatically imported into the project itself I'd gladly add those as well. The problem is that I can't include multiple DLLs with the exact same classes. But if I verified your invoice number I'd gladly compile the platform specific DLLs for you and send them over. It only takes a few minutes to do as I just need to set the appropriate symbols for each platform.
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
    @Dustin Horne: Thanks for the answer! In that case it makes no sense to have dlls, as they are only useful if there is a way to just have one for all the platforms. I still consider to buy it.
     
  8. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Thanks Dantus! Yes, I wish there was a good clean way to make a single DLL that would work for all platforms. It may be possible but it would require stripping out a bunch of functionality and the only one I'm not sure I could workaround is the security flags for the reflection pieces which are necessary to ensure no dynamic code is used for iOS. If you have any other questions or need some assistance, definitely let me know.

    Thanks,

    ~Dustin
     
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
  10. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Are there any particular scenarios that people would like to see demonstrated? My latest blog post shows basic implementation. I'm intending to demonstrate utilizing it with WWW to post data a web server and deserialize in my next article, but wanted to make sure I was covering topics that people were interested in.
     
  11. DMinsky

    DMinsky

    Joined:
    May 20, 2012
    Posts:
    16
    Great work! But... there is some issues.

    I try to make deserialization like this:
    Code (csharp):
    1.  
    2. levelSettings = JsonConvert.DeserializeObject<Dictionary<string, LevelBase>>( levelSettingsFile.text, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto } );
    3.  
    Where LevelBase is base class for three other classes. In serialized string I have derived classes:
    Code (csharp):
    1.  
    2. "1_1": {
    3.     "$type": "LevelRegular, Assembly-CSharp",
    4.     "moneyReward": 100,
    5.     "resources": {
    6.       "clover": 1
    7.     },
    8.     "id": "1_1",
    9.     "duration": -1
    10.   },
    11.   "1_2": {
    12.     "$type": "LevelRegular, Assembly-CSharp",
    13.     "moneyReward": 800,
    14.     "resources": {
    15.       "clover": 3,
    16.       "red_grape": 3
    17.     },
    18.     "id": "1_2",
    19.     "duration": 150.0
    20.   }
    21. }
    22.  
    Aaaand when I run this code on iOS device, I get this:
    Code (csharp):
    1.  
    2. (Filename: /Applications/buildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 54)
    3.  
    4. ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.GenericEqualityComparer`1<Newtonsoft.Json.Serialization.DefaultSerializationBinder/TypeNameKey>:.ctor ()' while running with --aot-only.
    5.  
    6.   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    7. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    8.   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    9.   at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    10.   at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    11.   at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
    12.   at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
    13.   at System.Collections.Generic.EqualityComparer`1[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey]..cctor () [0x00000] in <filename unknown>:0
    14. Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Collections.Generic.EqualityComparer`1
    15.   at System.Collections.Generic.Dictionary`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type].Init (Int32 capacity, IEqualityComparer`1 hcp) [0x00000] in <filename unknown>:0
    16.   at System.Collections.Generic.Dictionary`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type]..ctor () [0x00000] in <filename unknown>:0
    17.   at Newtonsoft.Json.Utilities.ThreadSafeStore`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type].AddValue (TypeNameKey key) [0x00000] in <filename unknown>:0
    18.   at Newtonsoft.Json.Utilities.ThreadSafeStore`2[Newtonsoft.Json.Serialization.DefaultSerializationBinder+TypeNameKey,System.Type].Get (TypeNameKey key) [0x00000] in <filename unknown>:0
    19.   at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0
    20.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0
    21. Rethrow as JsonSerializationException: Error resolving type specified in JSON 'LevelRegular, Assembly-CSharp'.
    22.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0
    23.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue) [0x00000] in <filename unknown>:0
    24.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0
    25.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary (IWrappedDictionary dictionary, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonDictionaryContract contract, System.String id) [0x00000] in <filename unknown>:0
    26.  
    27. (Filename:  Line: -1)
    28.  
    Any ideas?
     
  12. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Hmm... appears to be an issue with TypeNameHandling. Do you have Skype? I'd like to work with you to get it fixed ASAP.
     
  13. DMinsky

    DMinsky

    Joined:
    May 20, 2012
    Posts:
    16
    Yep, my skype: dmitry.minsky
     
  14. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    This has been addressed and fixed. Version 1.0.1 has been submitted to the Asset Store and is awaiting approval. IOS 5 seemed to have an issue with structs that implement IEquatable which was being used within Json .Net.
     
  15. tzrafi

    tzrafi

    Joined:
    Aug 6, 2013
    Posts:
    1
    Dustin, thanks for taking the time to create this port of JSON.NET. It's been much needed. Our company was considering our own port when yours showed up. I have been integrating it into our game but our team is hitting lots of AOT errors when attempting to deserialize data on a device.

    More specifically, the library seems to be unable to resolve type names for reasons we can't guess and it seems to crash deserializing properties that are of type List<> or Dictionary<,> where the generic arguments are not mscorlib types but happen to work fine if they are fields. It also happens if the generic types are abstract. I get the same exceptions that DMinsky is getting.

    Secondly, our company uses a set of contracts that are in a shared DLL between our client and server and for various reasons need to use the WCF data contract attributes which the official JSON.NET library interoperates with. I've went through the code and saw you ripped out support for it. The marketing material didn't call out what functionality was ripped out or what version of the JSON.NET library this was even based on. Can you add this back in ASAP? This was an important part of why we paid money for it vs rolling our own library.
     
  16. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    tzrafi -

    Send me a private message with your Skype and I'll send you the update to fix the AOT errors with with type resolution and the IEquatable stuff. As for the DataContract support, I can take a look but I'd need to customize it for you. This is something I can probably do. I'll likely need to reimplement part of .NET (which I had to do for some other features) because there are some things that aren't available in Unity's mono implementation.
     
  17. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Specifically, the version of System.Runtime.Serialization that's included doesn't have the DataContractAttribute. This was likely stripped because System.Data is also not available.
     
  18. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Just a heads up. We've discovered an issue with generic collections not serializing properly in specific (but common) situations when used as properties. When used as Fields instead of Properties they work properly. I am working on a fix and will publish it as soon as it is complete and tested.
     
  19. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    I've submitted an update to the Asset Store to correct some bugs folks were seeing. I also implemented WCF data attribute support. The update is pending review and will be available as soon as Unity approves it. To those who have purchased, if you send me your Invoice number I can go ahead and get you the updated version right away as it has some important fixes.

    Notable Updates:

    Version 1.1.0
    =========
    Corrected bugs with incorrect platform symbols
    Improved Android support
    Added WCF Data support via:
    - DataContractAttribute
    - DataMemberAttribute
    - EnumMemberAttribute

    Created new test cases to cover previous bugs.
     
  20. SmellyDogs

    SmellyDogs

    Joined:
    Jul 16, 2013
    Posts:
    387
    How well does this actually work? I must admit I am totally cheezed off with every free JSON parser with Unity that I've tried.

    Specifically when I tried anything more than was utterly trivial they failed.

    What testing have you done on this project with real world JSON?
     
  21. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    I'm in the process of setting up some samples that work against an ASP .NET MVC application. I haven't personally used this port "real world" yet since I don't actually have any games. I'm a programmer by trade and learning the graphical bits is taking me quite some time to learn.

    So far it works pretty well. The 1.0.0 version that's in the Asset store does have a couple of bugs. I made a mistake with my conditional symbol checking before pushing to the asset store and the tests that had been run against iOS had been simple primitive types.

    The 1.1.0 version I just pushed has been tested more heavily against different scenarios. I created test cases that cover the previously found bugs and all are passing successfully now. We've covered testing on primitives but also the scenarios that were generating AOT errors in the Newtonsoft DLL:

    Classes
    Generic Collections
    Classes with Collections as Properties (and fields)
    Dictionaries (Keyed Collections were also failing in Web Player in the original Newtonsoft version).
    Enumerations

    The 1.1.0 version also corrects type name handling issues so where we have:

    Code (csharp):
    1.  
    2. var list = new List<SomeBaseClass>();
    3.  
    4. for(var i = 0; i < 4; i++)
    5. {
    6.     list.Add(new ClassThatInheritsBaseClass());
    7. }
    8.  
    9. var serialized = JsonConvert.SerializeObject(list, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
    10.  
    I do have one user that appears to have an edge case bug that I haven't been able to reproduce and I'm awaiting a repro for it so I can fix it right away, but there are several folks using it already. I've also been supplying them with the 1.1.0 update directly while waiting for asset store approval.
     
  22. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    118
    Hi there.

    I am very interested on using this with SignalR on my game. SignalR uses Newtonsoft to encode communication and I am having problems making it work with other platforms than Windows.

    Just a few questions:
    1) Is this working with Android and IOS with no problems?
    2) Can you test if it's compatible with WP8 and WinRT?
    3) Are any discounts planed in the future? Sorry to be asking this already, but even if I buy this package I am not sure that I'll get SignalR running on Android/IOS, and so 50$ it's a little to much to waste.

    Thanks in advance
     
  23. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Joel -

    Thanks for the interest. It is working on Android and IOS. There was an issue with the version I pushed to the Asset Store (dumb find/replace mistake by me resulting in incorrect compilation symbols) and we also discovered another bug. I've pushed a new version to the asset store that corrects the majority of the issues and it's awaiting approval.

    We also discovered another issue that took some work to figure out. There are some differences between the subset and full framework. If you're targeting the subset, everything works fine, however when targeting the full framework (this affects IOS only), and trying to serialize a class that exists in a different pre-compiled assembly an AOT error occurs.

    This is due to a call to GetValue() on a PropertyInfo object. This is also the same issue that NGUI has with the full framework on IOS as opposed to the subset. I'm working on implementing a workaround for it now. If it works as intended I'll also share it with the NGUI folks so they can fix their reflection issues if they still have some outstanding.

    I haven't run my full set of unit tests against WP8 or RT yet as I've been building out new tests related to the latest issues we've found with the framework versions. Once I've gotten all of the new unit tests created I'll throw them at the WP8 and W8 builds as well. I have a physical WP8 device (HTC 8X) to test on as well as multiple RT devices.

    As for SignalR, if you go down that route you're likely going to lose a lot of time. I'll try to explain best I can below:

    When it comes to communication between client and server there are a couple primary options. You can use socket connections where you open a persistent connection and communicate back and forth, or you can create request/response style connection. The latter is how HTTP works. It's a one-off where you create a connection, send a request, get a response and then the connection is closed. This is how RESTful services are implemented. Until recently, web browsers did not really support persistent connections as the web is designed to be stateless.

    Microsoft did add an alternative when they added full duplex support to WCF, allowing the client and server to communicate with eachother. Using netTCPBinding settings for your endpoint binding you can even create persistent connection. The problem with this, though, is that it's meant for communication between .NET applications and comes with all of the fun complexities of WCF.

    Then came WebSockets. These are designed to allow persistent connections between the client and the HTTP based server. There are a couple of components to this when using SignalR (there are other options available). SignalR has the server side component which consists of creating hubs that handle the connections, sessions and client communication. It also consist of a javascript client library that generates proxy classes for you and handles sending and receiving messages.

    The issue is that javascript in Unity is a bit different... it's not really javascript as you'd know it in the browser. SignalR relies on sending function calls in closures (self executing functions) back to the browser and when the browser deserializes, it executes those methods. You can't exactly do that with Unity since it's getting compiled and not truly dynamic like JavaScript is. Also, the javascript libraries for SignalR are built to do feature detection for browsers and react accordingly, falling back from websockets to long polling, to forever frame.

    Now we're not using a browser so you don't really need to understand long polling vs forever frame in the context of the browser, but you do need to be aware that web sockets are not supported on IIS until IIS 8, so even if you're using a browser that supports web sockets (or a client app), the server won't support it unless you're running Windows Server 2012 or higher (2008 R2 shipped with IIS 7.5) and you'll be stuck using polling connections.

    Now if you do have a web sockets capable server, there are ways to invoke and utilize SignalR from .NET native code and not just from javascript, but I couldn't tell you what platforms it would work on. You'd be best to try it with simple scenarios that didn't require any serialization or deserialization. Here's a link that gives you a basic example:

    http://blogs.microsoft.co.il/blogs/ranw/archive/2012/12/29/using-signalr-with-net-client.aspx

    In my opinion, if you were doing something with persistent connection like SignalR, you'd be best to leverage sockets instead.
     
    Last edited: Sep 30, 2013
  24. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    I've completed Version 1.2.0. I will publish it as soon as Unity Admins approve version 1.1.0 to give folks a chance to update. I've corrected the issue with using the Full Framework on IOS. Using reflection to get the values of properties, the GetValue method of the PropertyInfo class works properly under other platforms and under the .NET Subset but blows up in the Full Framework. I've reimplemented the value resolution so it will properly get the value under both the Full and Subset frameworks in IOS.

    As always, anyone that has purchased can send me their invoice number and I can immediately send you the version 1.2.0 update so you don't have to wait for the Asset Store approval. I've also setup a FastSpring account and will be selling it from my own website as well so once that's complete, folks who purchase via that route will be able to get immediate updates without the wait.
     
  25. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    118
    Dustin, first of all, thanks for the amazing and complete response. You took the time to explain everything so well that I'll probably end up buying the package just for your professionalism. :D

    I currently have a game running on top of SignalR. It's a Multiplayer cards game and me and my partner opted to use SignalR because it was simple, cheap and compatible with WP / WinRT. Now we want to expand our platforms and we are thinking on porting the game to Unity, but we will only do it if we can run the game in at least two other platforms. The SignalR client is sending and receiving messages to the server in the editor, but at least in Android it only sends messages and it throws an exception when receiving one and I think it really has to do with the Newtonsoft JSON parser. I still have to try in IOS and depending on the results we'll probably buy this package.

    Once again thanks for the amazing response and I'll keep following this thread closely.
     
  26. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Thanks for the kind words. ;) Tell you what, PM me with your Skype contact info. I'll get you the latest version and we'll make sure it's going to work. If it works for you, then you can buy it. That way you don't waste money if that turns out to not be the issue. Not to mention I've fixed some bugs and it'll be awhile before 1.2 hits the Asset Store since they haven't even approved 1.1 yet.
     
  27. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Announcement and Discount

    I'm still waiting for version 1.1.0 to get approved on the Asset Store. In the meantime, version 1.2.0 is complete. I've created a FastSpring store and made it available for purchase. I've you've purchased the 1.0.0 version already, contact me with your invoice number and I will get you version 1.2.0. When you purchase through my FastSpring store, an account is automatically created for you on my site, allowing you instance access to the newest versions rather than waiting for Unity to approve them.

    To celebrate the opening of the new store and the dashboard updates to my site, I've created some limited use coupon codes. These codes must be used when placing the order through FastSpring.

    The first code is good for 50% off and is good only for the first 5 users. Once it's gone, it's gone. The second code is good for 25% off and is good for 10 users. Enter the code during the checkout process.

    These Codes Are Gone

    http://sites.fastspring.com/dustinhorne/product/jsonnetforunity
     
    Last edited: Oct 7, 2013
  28. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    I added a couple more coupon uses. The above two coupons will be good through today.
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
    Hey Dustin,

    I purchased this package a few days ago in the Asset Store. First of all, well done!

    In general it works really well. For the built-in types of Unity, there is still some potential in my opinion. E.g. when I serialize a quaternion, it also serializes its euler angles and all other properties. Technically I understand why this happens, but as this is a Unity solution, it would make sense to have a custom serialization for those types.

    For your information:
    Earlier in this thread you mentioned the VectorX issue. The same issue occurs with Color and it can be resolved with the same workaround you used for VectorX.
     
  30. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Thanks Dantus! Yes it does serialize everything that it has access to. It will also serialize private property so long as you've used a [Serializeable] attribute on them. As for the Color issue, thanks for the head's up. I'll get that support added in ASAP. Also, if you could PM me with your Skype contact info I'll send you the latest version as it has some important fixes so that it will support both Full Framework and .NET Subset on IOS.
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
    I don't need the newest version. It works for me as I only use it for the web player right now, but thanks!
     
  32. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Sounds good, let me know if you run into any issues! Do you happen to have a list of the fields you wouldn't want serialized automatically for Quanternions? The same will likely hold true for Vectors (since they include things like magnitude). I'll look at creating custom serializers for these types.

    As soon as 1.1.0 gets approved (hopefully some time this century *ahem* asset store admins */ahem*) I'll post 1.2.1 which includes the fixup for the Color and Color32 classes.
     
  33. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    The FastSpring version has been updated to version 1.2.1.
     
  34. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Ok, I have an email out to the Asset Store admins as something wonky is going on. Awhile back I submitted version 1.0.1 with a minor update. Then I made a bug fix. 1.0.1 had not been reviewed yet so I submitted version 1.1.0 which cancelled my old submission (which was fine). I received an email that 1.1.0 had been accepted for review. That was one week ago... 1.1.0 is still in "Pending" status, and all of the sudden today I got an email that said 1.0.1 has been accepted for review (it should have been cancelled). Not sure what's going on and I apologize for the delay but I'm working to get the updates into the asset store as quickly as they'll process them.
     
  35. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Version 1.1.0 has now been approved and is on the asset store with the critical fixes. I'll be publishing 1.2.1 tonight.
     
  36. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Received an email from a customer who purchased the 1.0.0 version and had an issue with deserializing an object. If you were using the 1.0.0 version, the 1.1.0 version is available and will correct most issues but the 1.2.1 version fixes issues with serializing and deserializing objects in 3rd party assemblies and differences between Full and Subset frameworks. Message me with your invoice number or send me an email and I'll get you the 1.2.1 version right away.

    nebraskadev(at)gmail.com
     
  37. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    New domain name launched! I acquired parentElement.com from one of my previous employers and this is now my new company site:
    http://www.parentelement.com

    The old unity.dustinhorne.com domain name still works but will automatically redirect you to the new domain. It is possible you may still see the old website pertaining to a Silverlight product. If this is the case it means that the DNS for the domain has not fully propagated as I just updated it this morning so just check back in a little while.

    To Celebrate, I've added a 30% Launch discount for JSON .NET For Unity. This discount code is good for the first 10 users only.

    To Use Go To: JSON .NET for Unity

    The discount will be applied automatically.
     
    Last edited: Oct 7, 2013
  38. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Version 1.2.1 is now live On the Asset Store. The price has been reduced to $45. Additionally:

    This version provides improved support for both Full Framework and Subset targets. It also added special handling of the Color struct (just as previous versions did for Vector3) to avoid circular dependency messages (thanks to Dantus for finding this one).

    Version 1.2.2 is in progress and will be released soon. There are currently no known issues with 1.2.1 but there are a few warning messages that may appear on iOS or Mac and 1.2.2 will address these. They have no impact on functionality.
     
  39. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    I will be skipping straight to 1.2.3 which will be published to the Asset Store soon. I also wanted to announce that I've worked out an agreement with the author of the excellent Recast for Unity Asset (click to see it on the asset store). The upcoming version of Recast will now include Json modifications to support iOS and WebPlayer as well as some additional AI enhancements. If you haven't checked it out, I highly recommend it.
     
  40. 4ik0

    4ik0

    Joined:
    Oct 22, 2013
    Posts:
    3
    Hi! Great serializer, finally someone handles type resolving!

    but, I'm having a little problem... in web player deserialization fails with exception: MethodAccessException "Attempt to access private/protected method failed"
    I'm trying to deserealize config from file. Standalone works perfect. In Web, if I generate the same json in runtime, and then parse it right after that - everything works. Text file is loaded from resources.

    what could go wrong?

    BTW, config is array of types, all of them are inherited from one class (not abstract)
     
    Last edited: Oct 22, 2013
  41. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Hmm... Is there a chance you could get me a simple repro for it so I can take a look? Hit up my contact form and send me your Skype ID as well:

    http://www.dustinhorne.com/contact

    It shouldn't be doing that so I'd love to figure out exactly what's causing the issue since I'm getting close to finalizing a 1.2.3 release and I can get you a hotfix right away.
     
  42. 4ik0

    4ik0

    Joined:
    Oct 22, 2013
    Posts:
    3
    ok, ill try )

    BTW, config is array of class objects, all of them are inherited from one class (not abstract)

    upd: the form sent
     
    Last edited: Oct 22, 2013
  43. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Thanks, I'll get you added.
     
  44. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Just wanted to note that I'm working with 4ik0 on this. The serialization and deserialization are actually working just fine. The problem only occurs when he loads the serialized JSON from a file and is likely an encoding issue, but does not appear to be a bug with the JSON .NET asset.
     
  45. 4ik0

    4ik0

    Joined:
    Oct 22, 2013
    Posts:
    3
    looks like this, because same json works fine when located in memory
     
  46. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    UPDATE: For my recent version change I reconverted the whole solution so I could add back in support that had previously been removed. In doing so, I missed a few conditionals and integration with Windows Phone 8 is currently broken. I hope to have the fix completed today and 1.2.3 will be ready to submit to the Asset Store.

    Thanks,

    Dustin
     
  47. chaosmaker

    chaosmaker

    Joined:
    Jul 21, 2013
    Posts:
    13
    I am working on a MVC service that would communicate with a Unity client (web player) through www class with Json. As far as I know, MVC uses Json.NET for automatic serialization/deserialization of objects from requests.

    So my questions is; if I would use Json.Net for Unity 3.5+, is it possible to share all data through a lib and easily serialize and deserialize all data without writing any custom serialization/deserializing code for them? I used miniJson, LitJSON so far, but for complex types they don't work well, you have to write all packing, unpacking operations for your complex classes.

    Thanks in advance
     
  48. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    If you're targeting MVC 4 ( or WebAPI) then yes, it uses JSON .NET. And since this is just a modification of the original JSON .NET library it is completely compatible. In fact, I would highly recommend what you're asking. Create a separate class library project and use that same DLL in both your Unity and your MVC application. Your MVC application can target .NET 4, or 4.5... but you need to make sure your class library is built for .NET 3.5 so it can be used in Unity as well. Also, you'll want to make sure you don't introduce dependencies in your library that Unity doesn't support, like any System.Data.

    If you need any examples on how to use the WWW class to get it working with MVC I'd be happy to help. The trick is that you'll not want to use the WWWForm class in this case, even if you're doing a POST. I think you'll want to use the WWW constructor overload that takes the post data as a byte array:

    http://docs.unity3d.com/Documentation/ScriptReference/WWW-ctor.html
     
  49. chaosmaker

    chaosmaker

    Joined:
    Jul 21, 2013
    Posts:
    13
    Thanks! I'll check it out.
     
  50. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,068
    Great news! It took some effort but we are now properly working for Windows Phone 8. If you've purchased and need an update right away to support Windows Phone 8, PM me with your invoice number and I'll send it over. Otherwise I'll be pushing the 1.2.3 update today with the updates included and Unity will have it updated hopefully next week.