| Package | vegas.strings.json |
| Class | public class JSONSerializer |
| Inheritance | JSONSerializer Object |
| Implements | Serializer |
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() ) ;
}
| Property | Defined 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 | ||
| Property | Defined 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 | ||
| Method | Defined 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 | ||
| Method | Defined 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 | ||
| at | property |
protected var at:Number = 0The current position of the iterator in the source.
| ch | property |
protected var ch:String = The current character of the iterator in the source.
| indentor | property |
indentor:StringIndicates the indentor string representation.
public function get indentor():String public function set indentor(value:String):void| prettyIndent | property |
prettyIndent:intIndicates the pretty indent value.
public function get prettyIndent():int public function set prettyIndent(value:int):void| prettyPrinting | property |
prettyPrinting:BooleanIndicates the pretty printing flag value.
public function get prettyPrinting():Boolean public function set prettyPrinting(value:Boolean):void| source | property |
public var source:StringThe source to evaluate.
| JSONSerializer | () | Constructor |
public function JSONSerializer()Creates a new JSONSerializer instance.
| array | () | method |
protected function array():ArrayCheck the Array objects in the source expression.
ReturnsArray |
| 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 |
* — a string representing the data.
|
| error | () | method |
protected function error(m:String):voidThrows a JSONError with the passed-in message.
Parameters
m:String |
| isDigit | () | method |
protected function isDigit(c:String):BooleanIndicates if the passed-in character is a digit.
Parameters
c:String |
Boolean |
| isHexDigit | () | method |
protected function isHexDigit(c:String):BooleanIndicates if the passed-in character is a hexadecimal digit.
Parameters
c:String |
Boolean |
| key | () | method |
protected function key():*Indicates if the current character is a key.
Returns* |
| next | () | method |
protected function next():StringReturns the next character in the source String representation.
ReturnsString — 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:*):StringSerialize the specified value object passed-in argument.
Parameters
value:* |
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():voidCheck all white spaces.
| word | () | method |
protected function word():*Check all special words in the source to evaluate.
Returns* |