/// <param name="x">A JSONTokener object containing the source string.</param>
privatevoidfromtokener(JSONTokenerx)
{
intc;
stringkey;
if(x->next()=='%')
{
x->unescape();
}
x->back();
if(x->nextClean()!='{')
{
throw(Error.Generic("A JSONObject must begin with '{'"));
}
while(1)
{
c=x->nextClean();
switch(c)
{
case0:
throw(Error.Generic("A JSONObject must end with '}'"));
case'}':
return;
default:
x->back();
key=(string)x->nextObject();
break;
}
if(x->nextClean()!=':')
{
throw(Error.Generic("Expected a ':' after a key"));
}
objectobj=x->nextObject();
if(objectp(obj)&&obj->toNative)
myHashMap[key]=obj->toNative();
else
myHashMap[key]=obj;
myKeyIndexList+=({key});
switch(x->nextClean())
{
case',':
if(x->nextClean()=='}')
{
return;
}
x->back();
break;
case'}':
return;
default:
throw(Error.Generic("Expected a ',' or '}'"));
}
}
}
/// <summary>
/// Construct a JSONObject from a string.
/// </summary>
/// <param name="sJSON">A string beginning with '{' and ending with '}'.</param>
// public JSONObject(Hashtable map)
// By changing to arg to interface, all classes that implements IDictionary can be used
// public interface IDictionary : ICollection, IEnumerable
// Classes that implements IDictionary
// 1. BaseChannelObjectWithProperties - Provides a base implementation of a channel object that wants to provide a dictionary interface to its properties.
// 2. DictionaryBase - Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed collection of key-and-value pairs.
// 3. Hashtable - Represents a collection of key-and-value pairs that are organized based on the hash code of the key.
// 4. HybridDictionary - Implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.
// 5. ListDictionary - Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.
// 6. PropertyCollection - Contains the properties of a DirectoryEntry.
// 7. PropertyDescriptorCollection - Represents a collection of PropertyDescriptor objects.
// 8. SortedList - Represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index.
// 9. StateBag - Manages the view state of ASP.NET server controls, including pages. This class cannot be inherited.
// See ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsidictionaryclasstopic.htm
/// <summary>
/// Construct a JSONObject from a IDictionary
/// </summary>
/// <param name="map"></param>
/// <summary>
/// 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.
/// </summary>
/// <param name="key">A key string.</param>
/// <param name="val">An object to be accumulated under the key.</param>