| Property | Defined by | ||
|---|---|---|---|
JSON : JSONSerializer
JSON (JavaScript object Notation) is a lightweight data-interchange format. | vegas.string | ||
| JSON | property |
public var JSON:JSONSerializer
JSON (JavaScript object Notation) is a lightweight data-interchange format.
More information in the official site : http://www.JSON.org
Add Hexa Digits tool in deserialize method - eden inspiration
import vegas.string.JSON;
import vegas.string.errors.JSONError;
import system.Reflection ;
// --- Init
var a:Array = [2, true, "hello"] ;
var o:Object = { prop1 : 1 , prop2 : 2 } ;
var s:String = "hello world" ;
var n:Number = 4 ;
var b:Boolean = true ;
trace("# Serialize \r") ;
trace("- a : " + JSON.serialize( a ) ) ;
trace("- o : " + JSON.serialize( o ) ) ;
trace("- s : " + JSON.serialize( s ) ) ;
trace("- n : " + JSON.serialize( n ) ) ;
trace("- b : " + JSON.serialize( b ) ) ;
trace ("\r# Deserialize \r") ;
var source:String = '[ { "prop1" : 0xFF0000 , prop2:2, prop3:"hello", prop4:true} , 2, true, 3, [3, 2] ]' ;
o = JSON.deserialize(source) ;
var l:uint = o.length ;
for (var i:uint = 0 ; i < l ; i++)
{
trace("> " + i + " : " + o[i] + " -> typeof :: " + typeof(o[i])) ;
if (typeof(o[i]) == "object")
{
for (var each:String in o[i])
{
trace(" > " + each + " : " + o[i][each] + " :: " + Reflection.getClassName(o[i][each]) ) ;
}
}
}
trace ("\r# JSONError \r") ;
source = "[3, 2," ; // test1
// var source:String = '{"prop1":coucou"}' ; // test2
try
{
var errorObj:= JSON.deserialize(source) ;
}
catch( e:JSONError )
{
trace( e.toString() ) ;
}