≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
is json possible?
Posted by:
(you are not logged in)
Enter the missing letter in: "Internati?nal"
(you are not logged in)
Text:
[quote][b][/b] wrote: *** UPDATED *** Here the COMPLETE RECURSIVE SOLUTION (based on Mozilla documentation). [code] // ---------------------------------------------------------------------- // // ******************** Recursive JSON* Mozilla Sample ************************* // // * Works for all standar data (is recursive): string, number, boolean, Array, Object, null. // * Tested on CCB 6.3 // var mozilla_json = function () { this.parse = function (text) { return (eval('(' + text + ')')); } this.stringify = function (object) { if (object instanceof Object) { var text = ""; if (object.constructor === Array) { for (var i = 0; i < object.length; text += this.stringify(object[i]) + ",", i++); return "[" + text.substr(0, text.length - 1) + "]"; } if (object.toString !== Object.prototype.toString) { return "\"" + object.toString().replace(/"/g, "\\$&") + "\""; } for (var prop in object) { text += "\"" + prop.replace(/"/g, "\\$&") + "\":" + this.stringify(object[prop]) + ","; } return "{" + text.substr(0, text.length - 1) + "}"; } return typeof object === "string" ? "\"" + object.replace(/"/g, "\\$&") + "\"" : String(object); } } var JSON = new mozilla_json(); // ---------------------------------------------------------------------- // --> TEST // ---------------------------------------------------------------------- var someTextObj = '{"prop1":"text-value-one","prop2":"text-value-two","prop3":3,'; someTextObj += '"prop4":4.4444,"prop5":true,"prop6":false,"prop7":null,"prop8":[1,2,3],'; someTextObj += '"prop9":["one","two","three"], "prop10":{"subp1":"hello", "subp2":"world"},'; someTextObj += '"prop11":Infinity,"prop12":"\\n" }'; print(); print(" --> Test 1: use it to restore data from disk or stream ( JSON.parse ) --------------\n"); var myObj = JSON.parse(someTextObj); print("TEST OK... \"someTextObj\" parsed on ( \"myObj\" ).\n\n\n"); print(" --> Test 2: Get Fun..!, and access object variables: --------------------------------\n"); for (i in myObj) { print(" myObj." + i + " = " + myObj[i] + " --> Type: " + typeof (myObj[i])); } print("\n"); print(" myObj.prop8[0] = " + myObj.prop8[0] + " --> Type: " + typeof (myObj.prop8[0]) + " --> (value in Array)"); print(" myObj.prop9[1] = " + myObj.prop9[1] + " --> Type: " + typeof (myObj.prop9[1]) + " --> (value in Array)"); print(" myObj.prop10.subp1 = " + myObj.prop10.subp1 + " --> Type: " + typeof (myObj.prop10.subp1) + " --> (prop in Object)"); print(" myObj.prop10.subp2 = " + myObj.prop10.subp2 + " --> Type: " + typeof (myObj.prop10.subp2) + " --> (prop in Object)"); print("\n\n"); print(" --> Test 3: use it to store or stream ( JSON.stringify ) -----------------------------\n"); print(JSON.stringify(myObj) + "\n\n"); print(); [/code][/quote]
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