com.esri.arcgis.system
Class JSONObject

java.lang.Object
  extended by com.esri.arcgis.system.JSONObject
All Implemented Interfaces:
com.esri.arcgis.interop.RemoteObjRef, IJSONObject, ISupportErrorInfo, Serializable

public class JSONObject
extends Object
implements com.esri.arcgis.interop.RemoteObjRef, IJSONObject, ISupportErrorInfo

Simplified JSON API coclass

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

See Also:
Serialized Form

Constructor Summary
JSONObject()
          Constructs a JSONObject using ArcGIS Engine.
JSONObject(Object obj)
          Deprecated. As of ArcGIS 9.2, replaced by normal Java casts.
JSONObject theJSONObject = (JSONObject) obj;
 
Method Summary
 void add(String name, Object value)
          Adds new member name-value pair to the member collection.
 void addBoolean(String name, boolean value)
          Adds new member name-value pair to the member collection.
 void addDate(String name, Date value)
          Adds new member name-value pair to the member collection.
 void addDouble(String name, double value)
          Adds new member name-value pair to the member collection.
 void addDoubleEx(String name, double value, int precision)
          Adds new member name-value pair to the member collection.
 void addJSONArray(String name, IJSONArray value)
          Adds new member name-value pair to the member collection.
 void addJSONObject(String name, IJSONObject value)
          Adds new member name-value pair to the member collection.
 void addLong(String name, int value)
          Adds new member name-value pair to the member collection.
 void addNull(String name)
          Adds new member with the value of null to the member collection.
 void addString(String name, String value)
          Adds new member name-value pair to the member collection.
 void clearAll()
          Removes all members.
 void createMemberArray(String name, IJSONArray[] value)
          Creates and adds new member name-value pair to the member collection.
 void createMemberObject(String name, IJSONObject[] value)
          Creates and adds new member name-value pair to the member collection.
 boolean equals(Object o)
          Compare this object with another
static String getClsid()
          getClsid.
 void getMemberAt(int index, String[] name, Object[] value)
          Returns member name and value at a given index.
 int getMemberCount()
          Returns size of member collection.
 int hashCode()
          the hashcode for this object
 void interfaceSupportsErrorInfo(GUID riid)
          interfaceSupportsErrorInfo
 boolean isCaseSensitiveNames()
          Returns true if member name lookups are case-sensitive.
 boolean isValueNull(String name)
          Returns VARIANT_TRUE if member is undefined or member's value is null.
 void makeValueNull(String name)
          Make a designated member NULL.
 boolean memberExists(String name)
          Checks if a member with the given name exists.
 void parseJSON(IJSONReader pReader)
          Parses JSON object from IJSONReader into memory.
 void parseString(String json)
          Parses JSON object from string into memory.
 void removeMember(String name)
          Remove a member from the member collection.
 void setCaseSensitiveNames(boolean case_sensitive)
          Returns true if member name lookups are case-sensitive.
 void toJSON(String objectName, IJSONWriter pWriter)
          Converts IJSONObject to JSON representation using provided IJSONWriter.
 String toJSONString(IPropertySet props)
          Converts IJSONObject to JSON representation using IJSONWriter internally.
 boolean tryGetValue(String name, Object[] value)
          Returns member value for a given name.
 boolean tryGetValueAsArray(String name, IJSONArray[] value)
          Returns member value for a given name as IJSONArray.
 boolean tryGetValueAsBoolean(String name, boolean[] value)
          Returns member value for a given name as boolean.
 boolean tryGetValueAsDate(String name, Date[] value)
          Returns member value for a given name as DATE.
 boolean tryGetValueAsDouble(String name, double[] value)
          Returns member value for a given name as double.
 boolean tryGetValueAsLong(String name, int[] value)
          Returns member value for a given name as long.
 boolean tryGetValueAsObject(String name, IJSONObject[] value)
          Returns member value for a given name as IJSONObject.
 boolean tryGetValueAsString(String name, String[] value)
          Returns member value for a given name as string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.esri.arcgis.interop.RemoteObjRef
getJintegraDispatch, release
 

Constructor Detail

JSONObject

public JSONObject()
           throws IOException,
                  UnknownHostException
Constructs a JSONObject using ArcGIS Engine.

Throws:
IOException - if there are interop problems
UnknownHostException - if there are interop problems

JSONObject

public JSONObject(Object obj)
           throws IOException
Deprecated. As of ArcGIS 9.2, replaced by normal Java casts.
JSONObject theJSONObject = (JSONObject) obj;

Construct a JSONObject using a reference to such an object returned from ArcGIS Engine or Server. This is semantically equivalent to casting obj to JSONObject.

Parameters:
obj - an object returned from ArcGIS Engine or Server
Throws:
IOException - if there are interop problems
Method Detail

getClsid

public static String getClsid()
getClsid.


equals

public boolean equals(Object o)
Compare this object with another

Overrides:
equals in class Object

hashCode

public int hashCode()
the hashcode for this object

Overrides:
hashCode in class Object

parseString

public void parseString(String json)
                 throws IOException,
                        AutomationException
Parses JSON object from string into memory.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
parseString in interface IJSONObject
Parameters:
json - The json (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

parseJSON

public void parseJSON(IJSONReader pReader)
               throws IOException,
                      AutomationException
Parses JSON object from IJSONReader into memory. Useful if you want to have random acces to just a part of a JSON.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
parseJSON in interface IJSONObject
Parameters:
pReader - A reference to a com.esri.arcgis.system.IJSONReader (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

isCaseSensitiveNames

public boolean isCaseSensitiveNames()
                             throws IOException,
                                    AutomationException
Returns true if member name lookups are case-sensitive. Default value is true. Methods affected by this state change: MemberExists, IsValueNull and all TryGet... methods.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
isCaseSensitiveNames in interface IJSONObject
Returns:
The case_sensitive
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

setCaseSensitiveNames

public void setCaseSensitiveNames(boolean case_sensitive)
                           throws IOException,
                                  AutomationException
Returns true if member name lookups are case-sensitive. Default value is true. Methods affected by this state change: MemberExists, IsValueNull and all TryGet... methods.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
setCaseSensitiveNames in interface IJSONObject
Parameters:
case_sensitive - The case_sensitive (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

memberExists

public boolean memberExists(String name)
                     throws IOException,
                            AutomationException
Checks if a member with the given name exists.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
memberExists in interface IJSONObject
Parameters:
name - The name (in)
Returns:
The exists
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

isValueNull

public boolean isValueNull(String name)
                    throws IOException,
                           AutomationException
Returns VARIANT_TRUE if member is undefined or member's value is null. Returns VARIANT_FALSE if member exists and its value is not null.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
isValueNull in interface IJSONObject
Parameters:
name - The name (in)
Returns:
The isNull
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

getMemberCount

public int getMemberCount()
                   throws IOException,
                          AutomationException
Returns size of member collection.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
getMemberCount in interface IJSONObject
Returns:
The count
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

getMemberAt

public void getMemberAt(int index,
                        String[] name,
                        Object[] value)
                 throws IOException,
                        AutomationException
Returns member name and value at a given index.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
getMemberAt in interface IJSONObject
Parameters:
index - The index (in)
name - The name (out: use single element array)
value - A Variant (out: use single element array)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValue

public boolean tryGetValue(String name,
                           Object[] value)
                    throws IOException,
                           AutomationException
Returns member value for a given name. If member does not exist, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValue in interface IJSONObject
Parameters:
name - The name (in)
value - A Variant (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsDate

public boolean tryGetValueAsDate(String name,
                                 Date[] value)
                          throws IOException,
                                 AutomationException
Returns member value for a given name as DATE. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsDate in interface IJSONObject
Parameters:
name - The name (in)
value - The value (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsBoolean

public boolean tryGetValueAsBoolean(String name,
                                    boolean[] value)
                             throws IOException,
                                    AutomationException
Returns member value for a given name as boolean. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsBoolean in interface IJSONObject
Parameters:
name - The name (in)
value - The value (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsLong

public boolean tryGetValueAsLong(String name,
                                 int[] value)
                          throws IOException,
                                 AutomationException
Returns member value for a given name as long. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsLong in interface IJSONObject
Parameters:
name - The name (in)
value - The value (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsDouble

public boolean tryGetValueAsDouble(String name,
                                   double[] value)
                            throws IOException,
                                   AutomationException
Returns member value for a given name as double. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsDouble in interface IJSONObject
Parameters:
name - The name (in)
value - The value (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsString

public boolean tryGetValueAsString(String name,
                                   String[] value)
                            throws IOException,
                                   AutomationException
Returns member value for a given name as string. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsString in interface IJSONObject
Parameters:
name - The name (in)
value - The value (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsObject

public boolean tryGetValueAsObject(String name,
                                   IJSONObject[] value)
                            throws IOException,
                                   AutomationException
Returns member value for a given name as IJSONObject. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsObject in interface IJSONObject
Parameters:
name - The name (in)
value - A reference to a com.esri.arcgis.system.IJSONObject (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

tryGetValueAsArray

public boolean tryGetValueAsArray(String name,
                                  IJSONArray[] value)
                           throws IOException,
                                  AutomationException
Returns member value for a given name as IJSONArray. If member does not exist or type coercion fails, returns VARIANT_FALSE in 'success' parameter.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
tryGetValueAsArray in interface IJSONObject
Parameters:
name - The name (in)
value - A reference to a com.esri.arcgis.system.IJSONArray (out: use single element array)
Returns:
The success
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addDate

public void addDate(String name,
                    Date value)
             throws IOException,
                    AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addDate in interface IJSONObject
Parameters:
name - The name (in)
value - The value (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addBoolean

public void addBoolean(String name,
                       boolean value)
                throws IOException,
                       AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addBoolean in interface IJSONObject
Parameters:
name - The name (in)
value - The value (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addLong

public void addLong(String name,
                    int value)
             throws IOException,
                    AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addLong in interface IJSONObject
Parameters:
name - The name (in)
value - The value (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addDouble

public void addDouble(String name,
                      double value)
               throws IOException,
                      AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addDouble in interface IJSONObject
Parameters:
name - The name (in)
value - The value (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addString

public void addString(String name,
                      String value)
               throws IOException,
                      AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addString in interface IJSONObject
Parameters:
name - The name (in)
value - The value (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addNull

public void addNull(String name)
             throws IOException,
                    AutomationException
Adds new member with the value of null to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addNull in interface IJSONObject
Parameters:
name - The name (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

add

public void add(String name,
                Object value)
         throws IOException,
                AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
add in interface IJSONObject
Parameters:
name - The name (in)
value - A Variant (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addJSONObject

public void addJSONObject(String name,
                          IJSONObject value)
                   throws IOException,
                          AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addJSONObject in interface IJSONObject
Parameters:
name - The name (in)
value - A reference to a com.esri.arcgis.system.IJSONObject (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addJSONArray

public void addJSONArray(String name,
                         IJSONArray value)
                  throws IOException,
                         AutomationException
Adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addJSONArray in interface IJSONObject
Parameters:
name - The name (in)
value - A reference to a com.esri.arcgis.system.IJSONArray (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

createMemberObject

public void createMemberObject(String name,
                               IJSONObject[] value)
                        throws IOException,
                               AutomationException
Creates and adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
createMemberObject in interface IJSONObject
Parameters:
name - The name (in)
value - A reference to a com.esri.arcgis.system.IJSONObject (out: use single element array)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

createMemberArray

public void createMemberArray(String name,
                              IJSONArray[] value)
                       throws IOException,
                              AutomationException
Creates and adds new member name-value pair to the member collection. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
createMemberArray in interface IJSONObject
Parameters:
name - The name (in)
value - A reference to a com.esri.arcgis.system.IJSONArray (out: use single element array)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

makeValueNull

public void makeValueNull(String name)
                   throws IOException,
                          AutomationException
Make a designated member NULL.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
makeValueNull in interface IJSONObject
Parameters:
name - The name (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

toJSONString

public String toJSONString(IPropertySet props)
                    throws IOException,
                           AutomationException
Converts IJSONObject to JSON representation using IJSONWriter internally. 'props' parameter is to control IJSONWriter properties. It's safe to set it to NULL.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
toJSONString in interface IJSONObject
Parameters:
props - A reference to a com.esri.arcgis.system.IPropertySet (in)
Returns:
The outStr
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

toJSON

public void toJSON(String objectName,
                   IJSONWriter pWriter)
            throws IOException,
                   AutomationException
Converts IJSONObject to JSON representation using provided IJSONWriter. Useful when you have complex JSON response you want to combine from the output of several methods.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
toJSON in interface IJSONObject
Parameters:
objectName - The objectName (in)
pWriter - A reference to a com.esri.arcgis.system.IJSONWriter (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

removeMember

public void removeMember(String name)
                  throws IOException,
                         AutomationException
Remove a member from the member collection.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
removeMember in interface IJSONObject
Parameters:
name - The name (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

clearAll

public void clearAll()
              throws IOException,
                     AutomationException
Removes all members.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
clearAll in interface IJSONObject
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

addDoubleEx

public void addDoubleEx(String name,
                        double value,
                        int precision)
                 throws IOException,
                        AutomationException
Adds new member name-value pair to the member collection. Stores precision for use in ToJSON and ToJSONString. Returns E_FAIL if duplicate member is found.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Specified by:
addDoubleEx in interface IJSONObject
Parameters:
name - The name (in)
value - The value (in)
precision - The precision (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.

interfaceSupportsErrorInfo

public void interfaceSupportsErrorInfo(GUID riid)
                                throws IOException,
                                       AutomationException
interfaceSupportsErrorInfo

Description

Indicates whether the interface supports IErrorInfo.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Supported Platforms

Windows, Solaris, Linux

Specified by:
interfaceSupportsErrorInfo in interface ISupportErrorInfo
Parameters:
riid - A Structure: com.esri.arcgis.support.ms.stdole.GUID (in)
Throws:
IOException - If there are interop problems.
AutomationException - If the ArcObject component throws an exception.