Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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. https://www.allspark.com/forums/... |
||||
|
No, the current JavaScript engine doesn't include the JSON interface, unfortunately. Maybe you can find an implementation for it on the web and use that. |
||||
|
lacaca wrote: 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. No, because the Coppercube JavaScript engine is running via ES5 standards. ES6 and higher has JSON and many more things like Math.clamp. |
||||
|
Hi, I read your post and did try to figure out how to do it... I wrote this little code... hope it can help you.
|
||||
|
*** UPDATED *** Here the COMPLETE RECURSIVE SOLUTION (based on Mozilla documentation).
|
||||
|
Here the output on the CopperCube "Message Log" Window: --> Test 1: use it to restore data from disk or stream ( JSON.parse ) -------------- TEST OK... "someTextObj" parsed on ( "myObj" ). --> Test 2: Get Fun..!, and access object variables: -------------------------------- myObj.prop1 = text-value-one --> Type: string myObj.prop2 = text-value-two --> Type: string myObj.prop3 = 3 --> Type: number myObj.prop4 = 4.4444 --> Type: number myObj.prop5 = true --> Type: boolean myObj.prop6 = false --> Type: boolean myObj.prop7 = null --> Type: object myObj.prop8 = 1,2,3 --> Type: object myObj.prop9 = one,two,three --> Type: object myObj.prop10 = [object Object] --> Type: object myObj.prop11 = Infinity --> Type: number myObj.prop12 = --> Type: string myObj.prop8[0] = 1 --> Type: number --> (value in Array) myObj.prop9[1] = two --> Type: string --> (value in Array) myObj.prop10.subp1 = hello --> Type: string --> (prop in Object) myObj.prop10.subp2 = world --> Type: string --> (prop in Object) --> Test 3: use it to store or stream ( JSON.stringify ) ----------------------------- {"prop1":"text-value-one","prop2":"text-value-two","prop3":3,"prop4":4.4444,"prop5":true,"prop6":false,"prop7":null,"prop8":[1,2,3],"prop9":["one","two","three"],"prop10":{"subp1":"hello","subp2":"world"},"prop11":Infinity,"prop12":" "} |
||||
|
That's awesome - cheers ! always wanted to know how to do that so I can use sort & filter sections of data ... |
|