Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
is json possible?

mvdhoning
Registered User
Quote
2018-07-14 00:35:53

Found this old entry: https://www.ambiera.com/forum.php?t=4929 that hint that encoding and decoding json might be possible. (maybe only in the webgl target)
But both mentioned urls are not working anymore.
Is JSON possible and if so how?

var myObj = { "name":"John", "age":31, "city":"New York" };
var myJSON = JSON.stringify(myObj);
alert('Hello World!'+myObj.name);


is not the way to go, as JSON is not defined.


niko
Moderator
Quote
2018-07-14 05:36:59

Yes, you would have to include a Json parser library, then it would work.

You could also use eval() to parse the json, this would work. It is vulnerable to attacks, but if you are using it in a game only - for example for reading config files - this should be ok.


mvdhoning
Registered User
Quote
2018-07-14 21:41:25

eval works like a charm :-)

though a parser via an include sounds better, but no clue how to do that with coppercube as i dont know where to put it and how to refer to it.


mvdhoning
Registered User
Quote
2018-07-15 22:05:11

figured it out
on the scene node on the behaviour i added
the Before first drawing do something
on action i added multiple execute javascript actions
in the first execute javascript i added:
https://bestiejs.github.io/json3...
so now i can do as usual in the next execute javascript and maybe everywhere from coppercube:
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
print(obj.name);



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact