|
I am using JSON to transfer data back and forth between my database and my unity app. JSON is a nice alternative to XML that is faster. Currently I am passing (variable depth acyclic) tree structures. I have found a C# parser called litJSON that is compatible with all .net languages. An informative thread about this can be found at : http://answers.unity3d.com/questions/531/what-is-the-easiest-json-library-to-integrate-with-unity Here you may also find a useful script for getting the data out of the JSON string. All C# coders that are thinking about using JSON as a data carrier should check it out. But alas, I can not get it to work. My problem is that i am trying to use JavaScript and I am not able to access the objects made in C#. (Is this possible?) I've been trying for three days, and I am stuck. Can anyone point me towards a simple way of building a tree structure of objects in javascript based on a JSON string? I am a bit confused because the JSON parsers out there promising to do this are all JavaScript, not Unity JavaScript, and the eval() function does not exist in Unity Javascript (or does it?). How can I create a javascript object tree from JSON string (similar to eval()) at runtime.
(comments are locked)
|
|
If the JSON parser script that you're trying to use is C#, and you're trying to access the results from Javascript, you are most likely running into the compilation order problem. See this answer for details, but basically you may find that putting your JSON parser scripts into a new folder named "Plugins" (in your Assets folder), will solve your problem. Thank you. I did, and I got it to work now. Cheers. And as I read in the documentation, i cant go both ways, something has to compile first. This means I cannot write to the console when in C# (placed in the plugin folder). Guess this is something I will have to live with.
Jul 21 '10 at 06:42 AM
Jens T
Jens T - Would you mind posting a full solution to this problem yourself? I have to do this in the next few days, and a quick walkthrough would be immensely useful.
Jul 22 '10 at 05:29 AM
grey
I will. I just have to do it first. Planning to do it next week. Decided to have sit-down with a friend of mine who is "The lord of code" or something. I am the "Lord of Datastructures". Together we control the matrix.
Jul 25 '10 at 06:31 AM
Jens T
(comments are locked)
|
|
Sorry for the delay everybody. Here is an simplified version of the parser* Trying feeding it pure string first, then get it to work using a textasset. Then finally, try to get the WWW object coroutine bastard thing to work (with yield). And you need a class called Component (Comp) to get this to work. It should implement the following methods : setParentComponent(Comp), getComponentName():String, and a few more, you will notice them in the code. Hi! can you please give me a sample of the Component (Comp) class??
Aug 29 '11 at 04:55 PM
yuriythebest
(comments are locked)
|
|
I've also written a simple parser, which I think might be easier to use. It's up on the UnifyCommunity Wiki. Check it out.
(comments are locked)
|

irrelevant but i couldnt resist PRESS X TO JSON