Packagevegas.string.json
Classpublic class JSONSerializer
ImplementsSerializer

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() ) ;
     }
     



Public Properties
 PropertyDefined by
  indentor : String
Indicates the indentor string representation.
JSONSerializer
  prettyIndent : int
Indicates the pretty indent value.
JSONSerializer
  prettyPrinting : Boolean
Indicates the pretty printing flag value.
JSONSerializer
  source : String
The source to evaluate.
JSONSerializer
Public Methods
 MethodDefined by
  
Creates a new JSONSerializer instance.
JSONSerializer
  
deserialize(source:String):*
Parse a string and interpret the source code to the correct object construct.
JSONSerializer
  
serialize(value:*):String
Serialize the specified value object passed-in argument.
JSONSerializer
Property detail
atproperty
jsonparser var at:Number = 0

The current position of the iterator in the source.

chproperty 
jsonparser var ch:String = " "

The current character of the iterator in the source.

indentorproperty 
indentor:String  [read-write]

Indicates the indentor string representation.

Implementation
    public function get indentor():String
    public function set indentor(value:String):void
prettyIndentproperty 
prettyIndent:int  [read-write]

Indicates the pretty indent value.

Implementation
    public function get prettyIndent():int
    public function set prettyIndent(value:int):void
prettyPrintingproperty 
prettyPrinting:Boolean  [read-write]

Indicates the pretty printing flag value.

Implementation
    public function get prettyPrinting():Boolean
    public function set prettyPrinting(value:Boolean):void
sourceproperty 
public var source:String

The source to evaluate.

Constructor detail
JSONSerializer()constructor
public function JSONSerializer()

Creates a new JSONSerializer instance.

Method detail
array()method
jsonparser function array():Array

Check the Array objects in the source expression.

Returns
Array
deserialize()method 
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
source:String

Returns
* — a string representing the data.
error()method 
jsonparser function error(m:String):void

Throws a JSONError with the passed-in message.

Parameters
m:String
isDigit()method 
jsonparser function isDigit(c:String):Boolean

Indicates if the passed-in character is a digit.

Parameters
c:String

Returns
Boolean
isHexDigit()method 
jsonparser function isHexDigit(c:String):Boolean

Indicates if the passed-in character is a hexadecimal digit.

Parameters
c:String

Returns
Boolean
key()method 
jsonparser function key():*

Indicates if the current character is a key.

Returns
*
next()method 
jsonparser function next():String

Returns the next character in the source String representation.

Returns
String — the next character in the source String representation.
number()method 
jsonparser function number():*

Check the Number values in the source expression.

Returns
*
object()method 
jsonparser function object():*

Check the Object values in the source expression.

Returns
*
serialize()method 
public function serialize(value:*):String

Serialize the specified value object passed-in argument.

Parameters
value:*

Returns
String
string()method 
jsonparser function string():*

Check the string objects in the source expression.

Returns
*
value()method 
jsonparser function value():*

Evaluates the values in the source expression.

Returns
*
white()method 
jsonparser function white():void

Check all white spaces.

word()method 
jsonparser function word():*

Check all special words in the source to evaluate.

Returns
*