C# Class MiniJSON, swip3

This class encodes and decodes JSON strings. Spec. details, see http://www.json.org/ JSON uses Arrays and Objects. These correspond here to the datatypes ArrayList and Hashtable. All numbers are parsed to doubles.
显示文件 Open project: unit9/swip3 Class Usage Examples

Protected Properties

Property Type Description
lastDecode string
lastErrorIndex int

Public Methods

Method Description
ByteStringToFloat ( string s ) : float
DeserializeColor ( Hashtable t ) : Color
DeserializeDateTime ( Hashtable data ) : DateTime
DeserializeRect ( Hashtable t ) : Rect
DeserializeVector3 ( Hashtable t ) : Vector3
FloatToByteString ( float f ) : string
SerializeColor ( Color c ) : Hashtable
SerializeDateTime ( DateTime t ) : Hashtable
SerializeRect ( Rect r ) : Hashtable
SerializeVector3 ( Vector3 v ) : Hashtable
getLastErrorIndex ( ) : int

On decoding, this function returns the position at which the parse failed (-1 = no error).

getLastErrorSnippet ( ) : string

If a decoding error occurred, this function returns a piece of the JSON string at which the error took place. To ease debugging.

jsonDecode ( string json ) : object

Parses the string json into a value

jsonEncode ( object json ) : string

Converts a Hashtable / ArrayList / Dictionary(string,string) object into a JSON string

lastDecodeSuccessful ( ) : bool

On decoding, this function returns the position at which the parse failed (-1 = no error).

Protected Methods

Method Description
eatWhitespace ( char json, int &index ) : void
getLastIndexOfNumber ( char json, int index ) : int
lookAhead ( char json, int index ) : int
nextToken ( char json, int &index ) : int
parseArray ( char json, int &index ) : ArrayList
parseNumber ( char json, int &index ) : double
parseObject ( char json, int &index ) : Hashtable
parseString ( char json, int &index ) : string
parseValue ( char json, int &index, bool &success ) : object
serializeArray ( ArrayList anArray, StringBuilder builder ) : bool
serializeDictionary ( string>.Dictionary dict, StringBuilder builder ) : bool
serializeNumber ( double number, StringBuilder builder ) : void
serializeObject ( Hashtable anObject, StringBuilder builder ) : bool
serializeObjectOrArray ( object objectOrArray, StringBuilder builder ) : bool
serializeString ( string aString, StringBuilder builder ) : void
serializeValue ( object value, StringBuilder builder ) : bool

Method Details

ByteStringToFloat() public static method

public static ByteStringToFloat ( string s ) : float
s string
return float

DeserializeColor() public static method

public static DeserializeColor ( Hashtable t ) : Color
t Hashtable
return Color

DeserializeDateTime() public static method

public static DeserializeDateTime ( Hashtable data ) : DateTime
data Hashtable
return DateTime

DeserializeRect() public static method

public static DeserializeRect ( Hashtable t ) : Rect
t Hashtable
return Rect

DeserializeVector3() public static method

public static DeserializeVector3 ( Hashtable t ) : Vector3
t Hashtable
return Vector3

FloatToByteString() public static method

public static FloatToByteString ( float f ) : string
f float
return string

SerializeColor() public static method

public static SerializeColor ( Color c ) : Hashtable
c Color
return Hashtable

SerializeDateTime() public static method

public static SerializeDateTime ( DateTime t ) : Hashtable
t DateTime
return Hashtable

SerializeRect() public static method

public static SerializeRect ( Rect r ) : Hashtable
r Rect
return Hashtable

SerializeVector3() public static method

public static SerializeVector3 ( Vector3 v ) : Hashtable
v Vector3
return Hashtable

eatWhitespace() protected static method

protected static eatWhitespace ( char json, int &index ) : void
json char
index int
return void

getLastErrorIndex() public static method

On decoding, this function returns the position at which the parse failed (-1 = no error).
public static getLastErrorIndex ( ) : int
return int

getLastErrorSnippet() public static method

If a decoding error occurred, this function returns a piece of the JSON string at which the error took place. To ease debugging.
public static getLastErrorSnippet ( ) : string
return string

getLastIndexOfNumber() protected static method

protected static getLastIndexOfNumber ( char json, int index ) : int
json char
index int
return int

jsonDecode() public static method

Parses the string json into a value
public static jsonDecode ( string json ) : object
json string A JSON string.
return object

jsonEncode() public static method

Converts a Hashtable / ArrayList / Dictionary(string,string) object into a JSON string
public static jsonEncode ( object json ) : string
json object A Hashtable / ArrayList
return string

lastDecodeSuccessful() public static method

On decoding, this function returns the position at which the parse failed (-1 = no error).
public static lastDecodeSuccessful ( ) : bool
return bool

lookAhead() protected static method

protected static lookAhead ( char json, int index ) : int
json char
index int
return int

nextToken() protected static method

protected static nextToken ( char json, int &index ) : int
json char
index int
return int

parseArray() protected static method

protected static parseArray ( char json, int &index ) : ArrayList
json char
index int
return ArrayList

parseNumber() protected static method

protected static parseNumber ( char json, int &index ) : double
json char
index int
return double

parseObject() protected static method

protected static parseObject ( char json, int &index ) : Hashtable
json char
index int
return Hashtable

parseString() protected static method

protected static parseString ( char json, int &index ) : string
json char
index int
return string

parseValue() protected static method

protected static parseValue ( char json, int &index, bool &success ) : object
json char
index int
success bool
return object

serializeArray() protected static method

protected static serializeArray ( ArrayList anArray, StringBuilder builder ) : bool
anArray ArrayList
builder StringBuilder
return bool

serializeDictionary() protected static method

protected static serializeDictionary ( string>.Dictionary dict, StringBuilder builder ) : bool
dict string>.Dictionary
builder StringBuilder
return bool

serializeNumber() protected static method

protected static serializeNumber ( double number, StringBuilder builder ) : void
number double
builder StringBuilder
return void

serializeObject() protected static method

protected static serializeObject ( Hashtable anObject, StringBuilder builder ) : bool
anObject Hashtable
builder StringBuilder
return bool

serializeObjectOrArray() protected static method

protected static serializeObjectOrArray ( object objectOrArray, StringBuilder builder ) : bool
objectOrArray object
builder StringBuilder
return bool

serializeString() protected static method

protected static serializeString ( string aString, StringBuilder builder ) : void
aString string
builder StringBuilder
return void

serializeValue() protected static method

protected static serializeValue ( object value, StringBuilder builder ) : bool
value object
builder StringBuilder
return bool

Property Details

lastDecode protected_oe static_oe property

protected static string lastDecode
return string

lastErrorIndex protected_oe static_oe property

On decoding, this value holds the position at which the parse failed (-1 = no error).
protected static int lastErrorIndex
return int