UnityMol  0.9.6-875
UnityMol viewer / In developement
MiniJSON Class Reference
+ Collaboration diagram for MiniJSON:

Static Public Member Functions

static object JsonDecode (string json)
 
static string JsonEncode (object json)
 
static bool LastDecodeSuccessful ()
 
static int GetLastErrorIndex ()
 
static string GetLastErrorSnippet ()
 

Public Attributes

const int TOKEN_NONE = 0
 
const int TOKEN_CURLY_OPEN = 1
 
const int TOKEN_CURLY_CLOSE = 2
 
const int TOKEN_SQUARED_OPEN = 3
 
const int TOKEN_SQUARED_CLOSE = 4
 
const int TOKEN_COLON = 5
 
const int TOKEN_COMMA = 6
 
const int TOKEN_STRING = 7
 
const int TOKEN_NUMBER = 8
 
const int TOKEN_TRUE = 9
 
const int TOKEN_FALSE = 10
 
const int TOKEN_NULL = 11
 

Protected Member Functions

Hashtable ParseObject (char[] json, ref int index)
 
ArrayList ParseArray (char[] json, ref int index)
 
object ParseValue (char[] json, ref int index, ref bool success)
 
string ParseString (char[] json, ref int index)
 
double ParseNumber (char[] json, ref int index)
 
int GetLastIndexOfNumber (char[] json, int index)
 
void EatWhitespace (char[] json, ref int index)
 
int LookAhead (char[] json, int index)
 
int NextToken (char[] json, ref int index)
 
bool SerializeObjectOrArray (object objectOrArray, StringBuilder builder)
 
bool SerializeObject (Hashtable anObject, StringBuilder builder)
 
bool SerializeArray (ArrayList anArray, StringBuilder builder)
 
bool SerializeValue (object value, StringBuilder builder)
 
void SerializeString (string aString, StringBuilder builder)
 
void SerializeNumber (double number, StringBuilder builder)
 

Protected Attributes

int lastErrorIndex = -1
 
string lastDecode = ""
 

Static Protected Attributes

static MiniJSON instance = new MiniJSON()
 

Private Attributes

const int BUILDER_CAPACITY = 2000
 

Detailed Description

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.

Definition at line 84 of file MiniJSON.cs.

Member Function Documentation

void MiniJSON.EatWhitespace ( char[]  json,
ref int  index 
)
protected

Definition at line 417 of file MiniJSON.cs.

Referenced by NextToken(), ParseNumber(), and ParseString().

+ Here is the caller graph for this function:

static int MiniJSON.GetLastErrorIndex ( )
static

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

Returns

Definition at line 175 of file MiniJSON.cs.

References instance, and lastErrorIndex.

static string MiniJSON.GetLastErrorSnippet ( )
static

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

To ease debugging.

Returns

Definition at line 185 of file MiniJSON.cs.

References instance, lastDecode, and lastErrorIndex.

int MiniJSON.GetLastIndexOfNumber ( char[]  json,
int  index 
)
protected

Definition at line 406 of file MiniJSON.cs.

Referenced by ParseNumber().

+ Here is the caller graph for this function:

static object MiniJSON.JsonDecode ( string  json)
static

Parses the string json into a value

Parameters
jsonA JSON string.
Returns
An ArrayList, a Hashtable, a double, a string, null, true, or false

Definition at line 114 of file MiniJSON.cs.

References instance, lastDecode, lastErrorIndex, and ParseValue().

Referenced by ParseData.ParsePDB.ReadJson.ReadFile().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static string MiniJSON.JsonEncode ( object  json)
static

Converts a Hashtable / ArrayList object into a JSON string

Parameters
jsonA Hashtable / ArrayList
Returns
A JSON encoded string, or null if object 'json' is not serializable

Definition at line 155 of file MiniJSON.cs.

References instance, and SerializeValue().

+ Here is the call graph for this function:

static bool MiniJSON.LastDecodeSuccessful ( )
static

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

Returns

Definition at line 166 of file MiniJSON.cs.

References instance, and lastErrorIndex.

int MiniJSON.LookAhead ( char[]  json,
int  index 
)
protected

Definition at line 426 of file MiniJSON.cs.

References NextToken().

Referenced by ParseArray(), ParseObject(), and ParseValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int MiniJSON.NextToken ( char[]  json,
ref int  index 
)
protected

Definition at line 432 of file MiniJSON.cs.

References EatWhitespace(), TOKEN_COLON, TOKEN_COMMA, TOKEN_CURLY_CLOSE, TOKEN_CURLY_OPEN, TOKEN_FALSE, TOKEN_NONE, TOKEN_NULL, TOKEN_NUMBER, TOKEN_SQUARED_CLOSE, TOKEN_SQUARED_OPEN, TOKEN_STRING, and TOKEN_TRUE.

Referenced by LookAhead(), ParseArray(), ParseObject(), and ParseValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ArrayList MiniJSON.ParseArray ( char[]  json,
ref int  index 
)
protected

Definition at line 249 of file MiniJSON.cs.

References LookAhead(), NextToken(), ParseValue(), TOKEN_COMMA, TOKEN_NONE, and TOKEN_SQUARED_CLOSE.

Referenced by ParseValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double MiniJSON.ParseNumber ( char[]  json,
ref int  index 
)
protected

Definition at line 393 of file MiniJSON.cs.

References EatWhitespace(), and GetLastIndexOfNumber().

Referenced by ParseValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Hashtable MiniJSON.ParseObject ( char[]  json,
ref int  index 
)
protected

Definition at line 203 of file MiniJSON.cs.

References LookAhead(), NextToken(), ParseString(), ParseValue(), TOKEN_COLON, TOKEN_COMMA, TOKEN_CURLY_CLOSE, and TOKEN_NONE.

Referenced by ParseValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string MiniJSON.ParseString ( char[]  json,
ref int  index 
)
protected

Definition at line 316 of file MiniJSON.cs.

References EatWhitespace().

Referenced by ParseObject(), and ParseValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

object MiniJSON.ParseValue ( char[]  json,
ref int  index,
ref bool  success 
)
protected

Definition at line 280 of file MiniJSON.cs.

References LookAhead(), NextToken(), ParseArray(), ParseNumber(), ParseObject(), ParseString(), TOKEN_CURLY_OPEN, TOKEN_FALSE, TOKEN_NONE, TOKEN_NULL, TOKEN_NUMBER, TOKEN_SQUARED_OPEN, TOKEN_STRING, and TOKEN_TRUE.

Referenced by JsonDecode(), ParseArray(), and ParseObject().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool MiniJSON.SerializeArray ( ArrayList  anArray,
StringBuilder  builder 
)
protected

Definition at line 541 of file MiniJSON.cs.

References SerializeValue().

Referenced by SerializeObjectOrArray(), and SerializeValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MiniJSON.SerializeNumber ( double  number,
StringBuilder  builder 
)
protected

Definition at line 631 of file MiniJSON.cs.

Referenced by SerializeValue().

+ Here is the caller graph for this function:

bool MiniJSON.SerializeObject ( Hashtable  anObject,
StringBuilder  builder 
)
protected

Definition at line 514 of file MiniJSON.cs.

References SerializeString(), and SerializeValue().

Referenced by SerializeObjectOrArray(), and SerializeValue().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool MiniJSON.SerializeObjectOrArray ( object  objectOrArray,
StringBuilder  builder 
)
protected

Definition at line 503 of file MiniJSON.cs.

References SerializeArray(), and SerializeObject().

+ Here is the call graph for this function:

void MiniJSON.SerializeString ( string  aString,
StringBuilder  builder 
)
protected

Definition at line 597 of file MiniJSON.cs.

Referenced by SerializeObject(), and SerializeValue().

+ Here is the caller graph for this function:

bool MiniJSON.SerializeValue ( object  value,
StringBuilder  builder 
)
protected

Definition at line 564 of file MiniJSON.cs.

References SerializeArray(), SerializeNumber(), SerializeObject(), and SerializeString().

Referenced by JsonEncode(), SerializeArray(), and SerializeObject().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const int MiniJSON.BUILDER_CAPACITY = 2000
private

Definition at line 99 of file MiniJSON.cs.

MiniJSON MiniJSON.instance = new MiniJSON()
staticprotected
string MiniJSON.lastDecode = ""
protected

Definition at line 107 of file MiniJSON.cs.

Referenced by GetLastErrorSnippet(), and JsonDecode().

int MiniJSON.lastErrorIndex = -1
protected

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

Definition at line 106 of file MiniJSON.cs.

Referenced by GetLastErrorIndex(), GetLastErrorSnippet(), JsonDecode(), and LastDecodeSuccessful().

const int MiniJSON.TOKEN_COLON = 5

Definition at line 91 of file MiniJSON.cs.

Referenced by NextToken(), and ParseObject().

const int MiniJSON.TOKEN_COMMA = 6

Definition at line 92 of file MiniJSON.cs.

Referenced by NextToken(), ParseArray(), and ParseObject().

const int MiniJSON.TOKEN_CURLY_CLOSE = 2

Definition at line 88 of file MiniJSON.cs.

Referenced by NextToken(), and ParseObject().

const int MiniJSON.TOKEN_CURLY_OPEN = 1

Definition at line 87 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().

const int MiniJSON.TOKEN_FALSE = 10

Definition at line 96 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().

const int MiniJSON.TOKEN_NONE = 0

Definition at line 86 of file MiniJSON.cs.

Referenced by NextToken(), ParseArray(), ParseObject(), and ParseValue().

const int MiniJSON.TOKEN_NULL = 11

Definition at line 97 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().

const int MiniJSON.TOKEN_NUMBER = 8

Definition at line 94 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().

const int MiniJSON.TOKEN_SQUARED_CLOSE = 4

Definition at line 90 of file MiniJSON.cs.

Referenced by NextToken(), and ParseArray().

const int MiniJSON.TOKEN_SQUARED_OPEN = 3

Definition at line 89 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().

const int MiniJSON.TOKEN_STRING = 7

Definition at line 93 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().

const int MiniJSON.TOKEN_TRUE = 9

Definition at line 95 of file MiniJSON.cs.

Referenced by NextToken(), and ParseValue().


The documentation for this class was generated from the following file: