C# Class Extensions.JSON

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. Pulled from http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
Show file Open project: h07r0d/Netduino-Aquarium-Controller

Public Methods

Method Description
JsonDecode ( string json ) : object

Parses the string json into a value

JsonDecode ( string json, bool &success ) : object

Parses the string json into a value; and fills 'success' with the successfullness of the parse.

JsonDecodeConfig ( string configFile ) : object
JsonDecodeFromFile ( string file ) : object
JsonDecodeFromVar ( string file ) : object

Decodes a JSON string stored in a text file. Assumes the string is defined as a JS variable.

JsonEncode ( object json ) : string

Converts a Hashtable / ArrayList object into a JSON string

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, bool &success ) : ArrayList
ParseNumber ( char json, int &index, bool &success ) : double
ParseObject ( char json, int &index, bool &success ) : Hashtable
ParseString ( char json, int &index, bool &success ) : string
ParseValue ( char json, int &index, bool &success ) : object
SerializeArray ( ArrayList anArray, StringBuilder builder ) : bool
SerializeNumber ( double number, StringBuilder builder ) : bool
SerializeObject ( Hashtable anObject, StringBuilder builder ) : bool
SerializeString ( string aString, StringBuilder builder ) : bool
SerializeValue ( object value, StringBuilder builder ) : bool

Method Details

EatWhitespace() protected static method

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

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

JsonDecode() public static method

Parses the string json into a value; and fills 'success' with the successfullness of the parse.
public static JsonDecode ( string json, bool &success ) : object
json string A JSON string.
success bool Successful parse?
return object

JsonDecodeConfig() public static method

public static JsonDecodeConfig ( string configFile ) : object
configFile string
return object

JsonDecodeFromFile() public static method

public static JsonDecodeFromFile ( string file ) : object
file string
return object

JsonDecodeFromVar() public static method

Decodes a JSON string stored in a text file. Assumes the string is defined as a JS variable.
public static JsonDecodeFromVar ( string file ) : object
file string File to open for decoding
return object

JsonEncode() public static method

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

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, bool &success ) : ArrayList
json char
index int
success bool
return System.Collections.ArrayList

ParseNumber() protected static method

protected static ParseNumber ( char json, int &index, bool &success ) : double
json char
index int
success bool
return double

ParseObject() protected static method

protected static ParseObject ( char json, int &index, bool &success ) : Hashtable
json char
index int
success bool
return System.Collections.Hashtable

ParseString() protected static method

protected static ParseString ( char json, int &index, bool &success ) : string
json char
index int
success bool
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 System.Collections.ArrayList
builder StringBuilder
return bool

SerializeNumber() protected static method

protected static SerializeNumber ( double number, StringBuilder builder ) : bool
number double
builder StringBuilder
return bool

SerializeObject() protected static method

protected static SerializeObject ( Hashtable anObject, StringBuilder builder ) : bool
anObject System.Collections.Hashtable
builder StringBuilder
return bool

SerializeString() protected static method

protected static SerializeString ( string aString, StringBuilder builder ) : bool
aString string
builder StringBuilder
return bool

SerializeValue() protected static method

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