Packagevegas.strings.json
Classpublic class JSONSerializer
InheritanceJSONSerializer Inheritance Object
Implements Serializer

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 core.getClassName ;
     
     import vegas.strings.JSON;
     import vegas.strings.JSONError;
     
     // --- 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") ;
     
     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 ("Deserialize") ;
     
     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] + " :: " + getClassName(o[i][each]) ) ;
             }
         }
     }
     
     trace ("JSONError") ;
     
     source = "[3, 2," ; // test1
     
     // var source:String = '{"prop1":coucou"}' ; // test2
     
     try
     {
        var errorObj:Object = 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
Protected Properties
 PropertyDefined By
  at : Number = 0
The current position of the iterator in the source.
JSONSerializer
  ch : String =
The current character of the iterator in the source.
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
Protected Methods
 MethodDefined By
  
array():Array
Check the Array objects in the source expression.
JSONSerializer
  
error(m:String):void
Throws a JSONError with the passed-in message.
JSONSerializer
  
isDigit(c:String):Boolean
Indicates if the passed-in character is a digit.
JSONSerializer
  
isHexDigit(c:String):Boolean
Indicates if the passed-in character is a hexadecimal digit.
JSONSerializer
  
key():*
Indicates if the current character is a key.
JSONSerializer
  
next():String
Returns the next character in the source String representation.
JSONSerializer
  
number():*
Check the Number values in the source expression.
JSONSerializer
  
object():*
Check the Object values in the source expression.
JSONSerializer
  
string():*
Check the string objects in the source expression.
JSONSerializer
  
value():*
Evaluates the values in the source expression.
JSONSerializer
  
white():void
Check all white spaces.
JSONSerializer
  
word():*
Check all special words in the source to evaluate.
JSONSerializer
Property Detail
atproperty
protected var at:Number = 0

The current position of the iterator in the source.

chproperty 
protected var ch:String =

The current character of the iterator in the source.

indentorproperty 
indentor:String

Indicates the indentor string representation.


Implementation
    public function get indentor():String
    public function set indentor(value:String):void
prettyIndentproperty 
prettyIndent:int

Indicates the pretty indent value.


Implementation
    public function get prettyIndent():int
    public function set prettyIndent(value:int):void
prettyPrintingproperty 
prettyPrinting:Boolean

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
protected 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 
protected function error(m:String):void

Throws a JSONError with the passed-in message.

Parameters

m:String

isDigit()method 
protected function isDigit(c:String):Boolean

Indicates if the passed-in character is a digit.

Parameters

c:String

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

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

Parameters

c:String

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

Indicates if the current character is a key.

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

Returns the next character in the source String representation.

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

Check the Number values in the source expression.

Returns
*
object()method 
protected 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 
protected function string():*

Check the string objects in the source expression.

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

Evaluates the values in the source expression.

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

Check all white spaces.

word()method 
protected function word():*

Check all special words in the source to evaluate.

Returns
*