This class is the concrete class of the JSON singleton.
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
Example
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() ) ;
}
jsonparser var at:Number = 0
The current position of the iterator in the source.
jsonparser var ch:String = " "
The current character of the iterator in the source.
indentor:String [read-write]
Indicates the indentor string representation.
Implementation
public function get indentor():String
public function set indentor(value:String):void
prettyIndent:int [read-write]
Indicates the pretty indent value.
Implementation
public function get prettyIndent():int
public function set prettyIndent(value:int):void
prettyPrinting:Boolean [read-write]
Indicates the pretty printing flag value.
Implementation
public function get prettyPrinting():Boolean
public function set prettyPrinting(value:Boolean):void
public var source:String
The source to evaluate.
public function JSONSerializer()
Creates a new JSONSerializer instance.
jsonparser function array():Array
Check the Array objects in the source expression.
Returns
public function deserialize(source:String):*
Parse a string and interpret the source code to the correct object construct.
Example :
"hello world" --> "hello world"
"0xFF" --> 255
"{a:1,"b":2}" --> {a:1,b:2}
Parameters
Returns
| * — a string representing the data.
|
jsonparser function error(m:String):void
Throws a JSONError with the passed-in message.
Parameters
jsonparser function isDigit(c:String):Boolean
Indicates if the passed-in character is a digit.
Parameters
Returns
jsonparser function isHexDigit(c:String):Boolean
Indicates if the passed-in character is a hexadecimal digit.
Parameters
Returns
jsonparser function key():*
Indicates if the current character is a key.
Returns
jsonparser function next():String
Returns the next character in the source String representation.
Returns
| String — the next character in the source String representation.
|
jsonparser function number():*
Check the Number values in the source expression.
Returns
jsonparser function object():*
Check the Object values in the source expression.
Returns
public function serialize(value:*):String
Serialize the specified value object passed-in argument.
Parameters
Returns
jsonparser function string():*
Check the string objects in the source expression.
Returns
jsonparser function value():*
Evaluates the values in the source expression.
Returns
jsonparser function white():void
Check all white spaces.
jsonparser function word():*
Check all special words in the source to evaluate.
Returns