Language

JSONArray.OptInt Method

Definition

Overloads

Name Description
OptInt(Int32)

Returns the value at index if it exists and is an int or can be coerced to an int.

OptInt(Int32, Int32)

Returns the value at index if it exists and is an int or can be coerced to an int.

OptInt(Int32)

Returns the value at index if it exists and is an int or can be coerced to an int.

[Android.Runtime.Register("optInt", "(I)I", "GetOptInt_IHandler")]
public virtual int OptInt(int index);
[<Android.Runtime.Register("optInt", "(I)I", "GetOptInt_IHandler")>]
abstract member OptInt : int -> int
override this.OptInt : int -> int

Parameters

index
Int32

The zero-based index of the value to read.

Returns

The number converted to an integer, or 0 if the value is missing, null, or cannot be converted. Numeric strings are parsed as Java doubles and then cast to integers; this can lose information.

Attributes

Remarks

Returns the value at index if it exists and is an int or can be coerced to an int. Returns 0 otherwise.

Java documentation for org.json.JSONArray.optInt(int).

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.

Applies to

OptInt(Int32, Int32)

Returns the value at index if it exists and is an int or can be coerced to an int.

[Android.Runtime.Register("optInt", "(II)I", "GetOptInt_IIHandler")]
public virtual int OptInt(int index, int fallback);
[<Android.Runtime.Register("optInt", "(II)I", "GetOptInt_IIHandler")>]
abstract member OptInt : int * int -> int
override this.OptInt : int * int -> int

Parameters

index
Int32

The zero-based index of the value to read.

fallback
Int32

The value to return if the requested value is missing, null, or cannot be converted to an integer.

Returns

The number converted to an integer, or fallback if conversion fails. Numeric strings are parsed as Java doubles and then cast to integers; this can lose information.

Attributes

Remarks

Returns the value at index if it exists and is an int or can be coerced to an int. Returns fallback otherwise.

Java documentation for org.json.JSONArray.optInt(int, int).

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.

Applies to