JSON
A JSONArray is an ordered sequence of values. Its external form is a string
wrapped in square brackets with commas between the values. The internal form
is an object having get() and opt() methods for accessing the values by
index, and put() methods for adding or replacing values. The values can be
any of these types: Boolean, JSONArray, JSONObject, Number, String, or the
JSONObject.NULL object.
The constructor can convert a JSON external form string into an
internal form Java object. The toString() method creates an external
form string.
A get() method returns a value if one can be found, and throws an exception
if one cannot be found. An opt() method returns a default value instead of
throwing an exception, and so is useful for obtaining optional values.
The generic get() and opt() methods return an object which you can cast or
query for type. There are also typed get() and opt() methods that do typing
checking and type coersion for you.
The texts produced by the toString() methods are very strict.
The constructors are more forgiving in the texts they will accept.
- An extra comma may appear just before the closing bracket.
- Strings may be quoted with single quotes.
- Strings do not need to be quoted at all if they do not contain leading
or trailing spaces, and if they do not contain any of these characters:
{ } [ ] / \ : ,
- Numbers may have the 0- (octal) or 0x- (hex) prefix.
Public Domain 2002 JSON.org
@author JSON.org
@version 0.1
Ported to C# by Are Bjolseth, teleplan.no
TODO:
1. Implement Custom exceptions
2. Add indexer JSONObject[i] = object, and object = JSONObject[i];
3. Add indexer JSONObject["key"] = object, and object = JSONObject["key"]
4. Add unit testing
5. Add log4net
6. Make get/put methods private, to force use of indexer instead?
The ArrayList where the JSONArray's properties are kept.
Construct an empty JSONArray
Construct a JSONArray from a JSONTokener.
A JSONTokener
Construct a JSONArray from a source string.
A string that begins with '[' and ends with ']'.
Construct a JSONArray from a Collection.
A Collection.
Get the object value associated with an index.
Use indexer instead!!! Added to be true to the original Java implementation
index subscript. The index must be between 0 and length()-1
An object value.
Get the ArrayList which is holding the elements of the JSONArray.
Use the indexer instead!! Added to be true to the orignal Java src
The ArrayList
Get the boolean value associated with an index.
The string values "true" and "false" are converted to boolean.
index subscript
The truth
Get the double value associated with an index.
index subscript
A double value
Get the int value associated with an index.
index subscript
The int value
Get the JSONArray associated with an index.
index subscript
A JSONArray value
Get the JSONObject associated with an index.
index subscript
A JSONObject value
Get the string associated with an index.
index subscript
A string value.
Determine if the value is null.
index subscript
true if the value at the index is null, or if there is no value.
Make a string from the contents of this JSONArray. The separator string
is inserted between each element.
Warning: This method assumes that the data structure is acyclical.
separator A string that will be inserted between the elements.
A string.
Get the length of the JSONArray.
Added to be true to the original Java implementation
Number of JSONObjects in array
Get the optional object value associated with an index.
index subscript
object at that index.
Get the optional boolean value associated with an index.
index subscript
The truth
Get the optional boolean value associated with an index.
It returns the defaultValue if there is no value at that index or if it is not
a Boolean or the String "true" or "false".
index subscript
The truth.
Get the optional double value associated with an index.
NaN is returned if the index is not found,
or if the value is not a number and cannot be converted to a number.
index subscript
The double value object
Get the optional double value associated with an index.
NaN is returned if the index is not found,
or if the value is not a number and cannot be converted to a number.
index subscript
The double value object
Get the optional int value associated with an index.
Zero is returned if the index is not found,
or if the value is not a number and cannot be converted to a number.
index subscript
The int value object
Get the optional int value associated with an index.
The defaultValue is returned if the index is not found,
or if the value is not a number and cannot be converted to a number.
index subscript
The default value
The int value object
Get the optional JSONArray associated with an index.
index subscript
A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
Get the optional JSONObject associated with an index.
Null is returned if the key is not found, or null if the index has
no value, or if the value is not a JSONObject.
index subscript
A JSONObject value
Get the optional string value associated with an index. It returns an
empty string if there is no value at that index. If the value
is not a string and is not null, then it is coverted to a string.
index subscript
A String value
Get the optional string associated with an index.
The defaultValue is returned if the key is not found.
index subscript
The default value
A string value
OMITTED:
public JSONArray put(bool val)
public JSONArray put(double val)
public JSONArray put(int val)
Append an object value.
An object value. The value should be a Boolean, Double, Integer, JSONArray, JSObject, or String, or the JSONObject.NULL object
this (JSONArray)
Put or replace a boolean value in the JSONArray.
The subscript. If the index is greater than the length of
the JSONArray, then null elements will be added as necessary to pad it out.
An object value.
this (JSONArray)
Produce a JSONObject by combining a JSONArray of names with the values
of this JSONArray.
A JSONArray containing a list of key strings. These will be paired with the values.
A JSONObject, or null if there are no names or if this JSONArray
Make an JSON external form string of this JSONArray. For compactness, no
unnecessary whitespace is added.
a printable, displayable, transmittable representation of the array.
Alternate to Java get/put method, by using indexer
Alternativ to Java, getArrayList, by using propery
Get the length of the JSONArray.
Using a propery instead of method
Summary description for JsonFacade.
Parse a Hashtable and return a JSON formatted string
Parse JSON formatted string and return a Hashtable
A JSONArray is an ordered sequence of values. Its external form is a string
wrapped in square brackets with commas between the values. The internal form
is an object having get() and opt() methods for accessing the values by
index, and put() methods for adding or replacing values. The values can be
any of these types: Boolean, JSONArray, JSONObject, Number, String, or the
JSONObject.NULL object.
The constructor can convert a JSON external form string into an
internal form Java object. The toString() method creates an external
form string.
A get() method returns a value if one can be found, and throws an exception
if one cannot be found. An opt() method returns a default value instead of
throwing an exception, and so is useful for obtaining optional values.
The generic get() and opt() methods return an object which you can cast or
query for type. There are also typed get() and opt() methods that do typing
checking and type coersion for you.
The texts produced by the toString() methods are very strict.
The constructors are more forgiving in the texts they will accept.
- An extra comma may appear just before the closing bracket.
- Strings may be quoted with single quotes.
- Strings do not need to be quoted at all if they do not contain leading
or trailing spaces, and if they do not contain any of these characters:
{ } [ ] / \ : ,
- Numbers may have the 0- (octal) or 0x- (hex) prefix.
Public Domain 2002 JSON.org
@author JSON.org
@version 0.1
Ported to C# by Are Bjolseth, teleplan.no
TODO:
1. Implement Custom exceptions
2. Add indexer JSONObject[i] = object, and object = JSONObject[i];
3. Add indexer JSONObject["key"] = object, and object = JSONObject["key"]
4. Add unit testing
5. Add log4net
6. Make get/put methods private, to force use of indexer instead?
The hash map where the JSONObject's properties are kept.
A shadow list of keys to enable access by sequence of insertion
It is sometimes more convenient and less ambiguous to have a NULL
object than to use C#'s null value.
JSONObject.NULL.toString() returns "null".
Construct an empty JSONObject.
Construct a JSONObject from a JSONTokener.
A JSONTokener object containing the source string.
Construct a JSONObject from a string.
A string beginning with '{' and ending with '}'.
Construct a JSONObject from a IDictionary
Accumulate values under a key. It is similar to the put method except
that if there is already an object stored under the key then a
JSONArray is stored under the key to hold all of the accumulated values.
If there is already a JSONArray, then the new value is appended to it.
In contrast, the put method replaces the previous value.
A key string.
An object to be accumulated under the key.
this
C# convenience method
The Hashtable
Alias to Java get method
Get the value object associated with a key.
A key string.
The object associated with the key.
Get the boolean value associated with a key.
A key string.
The truth.
Get the double value associated with a key.
A key string.
The double value
Get the int value associated with a key.
A key string
The integer value.
Get the JSONArray value associated with a key.
A key string
A JSONArray which is the value
Get the JSONObject value associated with a key.
A key string.
A JSONObject which is the value.
Get the string associated with a key.
A key string.
A string which is the value.
Determine if the JSONObject contains a specific key.
A key string.
true if the key exists in the JSONObject.
Get an enumeration of the keys of the JSONObject.
Added to be true to orginal Java implementation
Indexers are easier to use
Determine if the value associated with the key is null or if there is no value.
A key string
true if there is no value associated with the key or if the valus is the JSONObject.NULL object
Get the number of keys stored in the JSONObject.
The number of keys in the JSONObject.
Produce a JSONArray containing the names of the elements of this JSONObject
A JSONArray containing the key strings, or null if the JSONObject
Produce a string from a number.
Number value type object
String representation of the number
Get an optional value associated with a key.
A key string
An object which is the value, or null if there is no value.
Get an optional value associated with a key.
It returns false if there is no such key, or if the value is not
Boolean.TRUE or the String "true".
A key string.
bool value object
Get an optional value associated with a key.
It returns false if there is no such key, or if the value is not
Boolean.TRUE or the String "true".
A key string.
The preferred return value if conversion fails
bool value object
Get an optional double associated with a key,
or NaN if there is no such key or if its value is not a number.
If the value is a string, an attempt will be made to evaluate it as
a number.
A string which is the key.
A double value object
Get an optional double associated with a key,
or NaN if there is no such key or if its value is not a number.
If the value is a string, an attempt will be made to evaluate it as
a number.
A string which is the key.
The default
A double value object
Get an optional double associated with a key, or the
defaultValue if there is no such key or if its value is not a number.
If the value is a string, an attempt will be made to evaluate it as
number.
A key string.
An int object value
Get an optional double associated with a key, or the
defaultValue if there is no such key or if its value is not a number.
If the value is a string, an attempt will be made to evaluate it as
number.
A key string.
The default value
An int object value
Get an optional JSONArray associated with a key.
It returns null if there is no such key, or if its value is not a JSONArray
A key string
A JSONArray which is the value
Get an optional JSONObject associated with a key.
It returns null if there is no such key, or if its value is not a JSONObject.
A key string.
A JSONObject which is the value
Get an optional string associated with a key.
It returns an empty string if there is no such key. If the value is not
a string and is not null, then it is coverted to a string.
A key string.
A string which is the value.
Get an optional string associated with a key.
It returns the defaultValue if there is no such key.
A key string.
The default
A string which is the value.
Put a key/value pair in the JSONObject. If the value is null,
then the key will be removed from the JSONObject if it is present.
A key string.
An object which is the value. It should be of one of these
types: Boolean, Double, Integer, JSONArray, JSONObject, String, or the
JSONObject.NULL object.
JSONObject
Add a key value pair
Remove a object assosiateted with the given key
Append an array of JSONObjects to current object
Overridden to return a JSON formattet object as a string
JSON object as formatted string
Return the key for the associated index
Get/Add an object with the associated key
Return the number of JSON items in hashtable
Make a Null object
JSONObject.NULL is equivalent to the value that JavaScript calls null,
whilst C#'s null is equivalent to the value that JavaScript calls undefined.
Overriden to return "null"
null
A JSONTokener takes a source string and extracts characters and tokens from
it. It is used by the JSONObject and JSONArray constructors to parse
JSON source strings.
Public Domain 2002 JSON.org
@author JSON.org
@version 0.1
Ported to C# by Are Bjolseth, teleplan.no
- Implement Custom exceptions
- Add unit testing
- Add log4net
The index of the next character.
The source string being tokenized.
Construct a JSONTokener from a string.
A source string.
Back up one character. This provides a sort of lookahead capability,
so that you can test for a digit or letter before attempting to parse
the next number or identifier.
Get the hex value of a character (base16).
A character between '0' and '9' or between 'A' and 'F' or
between 'a' and 'f'.
An int between 0 and 15, or -1 if c was not a hex digit.
Determine if the source string still contains characters that next() can consume.
true if not yet at the end of the source.
Get the next character in the source string.
The next character, or 0 if past the end of the source string.
Consume the next character, and check that it matches a specified character
The character to match.
The character.
Get the next n characters.
The number of characters to take.
A string of n characters.
Get the next char in the string, skipping whitespace
and comments (slashslash and slashstar).
A character, or 0 if there are no more characters.
Return the characters up to the next close quote character.
Backslash processing is done. The formal JSON format does not
allow strings in single quotes, but an implementation is allowed to
accept them.
The quoting character, either " or '
A String.
Get the text up but not including the specified character or the
end of line, whichever comes first.
A delimiter character.
A string.
Get the text up but not including one of the specified delimeter
characters or the end of line, which ever comes first.
A set of delimiter characters.
A string, trimmed.
Get the next value as object. The value can be a Boolean, Double, Integer,
JSONArray, JSONObject, or String, or the JSONObject.NULL object.
An object.
Skip characters until the next character is the requested character.
If the requested character is not found, no characters are skipped.
A character to skip to.
The requested character, or zero if the requested character is not found.
Skip characters until past the requested string.
If it is not found, we are left at the end of the source.
A string to skip past.
Make a printable string of this JSONTokener.
" at character [myIndex] of [mySource]"
Unescape the source text. Convert %hh sequences to single characters,
and convert plus to space. There are Web transport systems that insist on
doing unnecessary URL encoding. This provides a way to undo it.
Convert %hh sequences to single characters, and convert plus to space.
A string that may contain plus and %hh sequences.
The unescaped string.
Public Domain 2002 JSON.org
@author JSON.org
@version 0.1
Ported to C# by Are Bjolseth, teleplan.no
Produce a string in double quotes with backslash sequences in all the right places.
A String
A String correctly formatted for insertion in a JSON message.