简体   繁体   中英

JSON-Parser for Unity3D and Flash

currently i am implementing an application in Unity3D (C#) that will be exported to Flash and WebPlayer Version. The Application uses JSON to communicate with the server. My question is: is there any JSON-Parser that works in Unity WebPlayer AND Flash?? i tried MiniJSON Flash Version already. After spending hours to make it to a clean export it decodes JSON in UnityWebPlayer but returns NULL in Flash. Is there any other way to parse a JSON string in Unity WebPlayer and Flash? Or is there another JSON-Parser that works in Flash too? I really searched a lot but either the people provide links to MiniJSON or suggest to wait for Unity3D version 4.0. I even tried the Proxy-Class feature of unity3D but couldnt get to run it on Flash side. Maybe someone could provide an example for it?

Thanks very much

I use LitJSON for Unity and had no problems when I built a web player version for testing purposes a while ago. I have no experience with Flash player but according to this presentation Unity and Flash, the best of both worlds! - Unite presentation slides page 18 ff. it should do the job.

No JSON library written in C# is likely to work with Unity's flash export (if you want strongly typed objects on the client side) because some key .net reflection pieces are not supported, even in the official 4.0 release. I asked Unity to sanction a supported JSON parser that could be used across desktop, web player and flash and it just didn't happen for this release.

I ended up using native AS3 stringify and parse methods on the client side and JSON.net on the server side. The tricky part is compensating for the name mangling that Unity does when it converts your C# to ActionScript. I was able to make this work without hard coding by using some of the standard ways to override parsing and serializing JSON strings, using a lot of describeType(). Since JSON.net is supported in their web player, I was able to use some #if FLASH pragmas to get both working well depending on build target.

So....it is possible, and perhaps I've done much of the hard work for you. If you want some examples let me know.

-Tray Weeds

Try this: https://github.com/ironmagma/jsonparse

It is completly written in UnityScript. Probably it helps and works in Flash Export. But i did not test it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM