JSONObject Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A modifiable set of name/value mappings.
[Android.Runtime.Register("org/json/JSONObject", DoNotGenerateAcw=true)]
public class JSONObject : Java.Lang.Object
[<Android.Runtime.Register("org/json/JSONObject", DoNotGenerateAcw=true)>]
type JSONObject = class
inherit Object
- Inheritance
- Attributes
Remarks
A modifiable set of name/value mappings. Names are unique, non-null strings. Values may be any mix of JSONObject JSONObjects
, JSONArray JSONArrays
, Strings, Booleans, Integers, Longs, Doubles or #NULL
. Values may not be null
, Double#isNaN() NaNs
, Double#isInfinite() infinities
, or of any type not listed here.
This class can coerce values to another type when requested. <ul> <li>When the requested type is a boolean, strings will be coerced using a case-insensitive comparison to "true" and "false". <li>When the requested type is a double, other Number
types will be coerced using Number#doubleValue() doubleValue
. Strings that can be coerced using Double#valueOf(String)
will be. <li>When the requested type is an int, other Number
types will be coerced using Number#intValue() intValue
. Strings that can be coerced using Double#valueOf(String)
will be, and then cast to int. <li>"lossy">When the requested type is a long, other <c>Number</c> types will be coerced using <c>Number#longValue() longValue</c>. Strings that can be coerced using <c>Double#valueOf(String)</c> will be, and then cast to long. This two-step conversion is lossy for very large values. For example, the string "9223372036854775806" yields the long 9223372036854775807.<li>When the requested type is a String, other non-null values will be coerced using String#valueOf(Object)
. Although null cannot be coerced, the sentinel value JSONObject#NULL
is coerced to the string "null". </ul>
This class can look up both mandatory and optional values: <ul> <li>Use get<i>Type</i>()
to retrieve a mandatory value. This fails with a JSONException
if the requested name has no value or if the value cannot be coerced to the requested type. <li>Use opt<i>Type</i>()
to retrieve an optional value. This returns a system- or user-supplied default if the requested name has no value or if the value cannot be coerced to the requested type. </ul>
<strong>Warning:</strong> this class represents null in two incompatible ways: the standard Java null
reference, and the sentinel value JSONObject#NULL
. In particular, calling put(name, null)
removes the named entry from the object but put(name, JSONObject.NULL)
stores an entry whose value is JSONObject.NULL
.
Instances of this class are not thread safe. Although this class is nonfinal, it was not designed for inheritance and should not be subclassed. In particular, self-use by overrideable methods is not specified. See Effective Java, 3rd edition Item 19, "Design and Document for inheritance or else prohibit it" for further information.
Java documentation for org.json.JSONObject
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
JSONObject() |
Creates a |
JSONObject(IDictionary) |
Creates a new |
JSONObject(IntPtr, JniHandleOwnership) |
A constructor used when creating managed representations of JNI objects; called by the runtime. |
JSONObject(JSONObject, String[]) |
Creates a new |
JSONObject(JSONTokener) |
Creates a new |
JSONObject(String) |
Creates a new |
Properties
Class |
Returns the runtime class of this |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
Null |
A sentinel value used to explicitly define a name with no value. |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
Methods
Accumulate(String, Object) |
Appends |
Append(String, Object) |
Appends values to the array mapped to |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
Get(String) |
Returns the value mapped by |
GetBoolean(String) |
Returns the value mapped by |
GetDouble(String) |
Returns the value mapped by |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetInt(String) |
Returns the value mapped by |
GetJSONArray(String) |
Returns the value mapped by |
GetJSONObject(String) |
Returns the value mapped by |
GetLong(String) |
Returns the value mapped by |
GetString(String) |
Returns the value mapped by |
Has(String) |
Returns true if this object has a mapping for |
IsNull(String) |
Returns true if this object has no mapping for |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
Keys() |
Returns an iterator of the |
Length() |
Returns the number of name/value mappings in this object. |
Names() |
Returns an array containing the string names in this object. |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
NumberToString(Number) |
Encodes the number as a JSON string. |
Opt(String) |
Returns the value mapped by |
OptBoolean(String, Boolean) |
Returns the value mapped by |
OptBoolean(String) |
Returns the value mapped by |
OptDouble(String, Double) |
Returns the value mapped by |
OptDouble(String) |
Returns the value mapped by |
OptInt(String, Int32) |
Returns the value mapped by |
OptInt(String) |
Returns the value mapped by |
OptJSONArray(String) |
Returns the value mapped by |
OptJSONObject(String) |
Returns the value mapped by |
OptLong(String, Int64) |
Returns the value mapped by |
OptLong(String) |
Returns the value mapped by |
OptString(String, String) |
Returns the value mapped by |
OptString(String) |
Returns the value mapped by |
Put(String, Boolean) |
Maps |
Put(String, Double) |
Maps |
Put(String, Int32) |
Maps |
Put(String, Int64) |
Maps |
Put(String, Object) |
Maps |
PutOpt(String, Object) |
Equivalent to |
Quote(String) |
Encodes |
Remove(String) |
Removes the named mapping if it exists; does nothing otherwise. |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
ToArray<T>() | (Inherited from Object) |
ToJSONArray(JSONArray) |
Returns an array with the values corresponding to |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
ToString(Int32) |
Encodes this object as a human readable JSON string for debugging, such as: |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wrap(Object) |
Wraps the given object if necessary. |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |