JSON (library)
Overview
Summary
Douglas Crockford's standard JSON library. Note that this library, or perhaps SpiderMonkey, does not seem to serialize and deserialize Dates correctly.
Contents
The JSON library is currently disabled in the core bootstrap, as it extends native objects and breaks for..in loops. I'll look into rewriting the JSON lib once the framework is officially in beta.
API
stringify(value, replacer, space)
Converts a JavaScript value to a valid JSON String
Serialize a JavaScript value to a JSON String:
var json = JSON.stringify([1, 2, 3, {a:1, b:'Hello'}]);
trace(json);
[1,2,3,{"a":1,"b":"Hello"}]
parse(text, reviver)
Converts a valid JSON String to a JavaScript value
Deserialize a JSON string to a javaScript object:
var value = JSON.parse('[1,2,3,{"a":1,"b":"Hello"}]')
Output.inspect(value);
Inspect: Array (depth:4, objects:1, values:5, time:0.0 seconds) -------------------------------------------------------------------------------- array => Array 0: 1 1: 2 2: 3 [3] => Object a: 1 b: "Hello"