- Home /
Anyone successful using native JSON libs with AS3?
I'm using native AS3 JSON library, so JSON.stringify() and JSON.parse(). I'm using this because of the shortcomings of C# reflection support in Unity's conversion.
However, this doesn't seem to work very well given the conversion process Unity goes through for C# to ActionScript. If I have a System.Collections.Generic.List and I try to serialize to JSON, I get some errors. Now in reality the object graph is much more robust so I have an object at the root, that contains other objects and properties, that could be lists, arrays or dictionaries, along with native types, i.e. string, int, etc.
Here is the AS3 error stack - not very helpful other than that ICollection_SyncRoot.
Error
at System::Exception/WithStackTrace()
at System.Collections.Generic::List$1/get ICollection_SyncRoot()
at JSON$/stringifySpecializedToString()
at JSON$/stringify()
I'm not quite sure this is a bug given that it's native Flash SDK, but is probably something not implemented correctly during Unity's conversion. Either way, another work around for JSON that uses reflection in either C# or AS3 with generic lists, dictionaries and native types would be sweet. I feel that in order for Unity's AS3 conversion to be taken seriously this serialization mechanism, or another supported one (using reflection) needs to be thought through by the Unity dev team.
I ran across this today https://gist.github.com/1601919 . Not sure if it will work though, as I haven't tested it yet. Not really native to AS3, though, but should work for both Flash and other builds.