Language

JSONObject.OptString Method

Definition

Overloads

Name Description
OptString(String)

Returns the value mapped by name if it exists, coercing it if necessary, or the empty string if no such mapping exists.

OptString(String, String)

Returns the value mapped by name if it exists, coercing it if necessary, or fallback if no such mapping exists.

OptString(String)

Returns the value mapped by name if it exists, coercing it if necessary, or the empty string if no such mapping exists.

[Android.Runtime.Register("optString", "(Ljava/lang/String;)Ljava/lang/String;", "GetOptString_Ljava_lang_String_Handler")]
public virtual string OptString(string? name);
[<Android.Runtime.Register("optString", "(Ljava/lang/String;)Ljava/lang/String;", "GetOptString_Ljava_lang_String_Handler")>]
abstract member OptString : string -> string
override this.OptString : string -> string

Parameters

name
String

The name of the value to read, or null if no name is supplied.

Returns

The mapped value converted to a string, or the empty string if the mapping is missing. Null converts to "null".

Attributes

Remarks

Returns the value mapped by name if it exists, coercing it if necessary, or the empty string if no such mapping exists.

Java documentation for org.json.JSONObject.optString(java.lang.String).

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

OptString(String, String)

Returns the value mapped by name if it exists, coercing it if necessary, or fallback if no such mapping exists.

[Android.Runtime.Register("optString", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "GetOptString_Ljava_lang_String_Ljava_lang_String_Handler")]
public virtual string OptString(string? name, string fallback);
[<Android.Runtime.Register("optString", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "GetOptString_Ljava_lang_String_Ljava_lang_String_Handler")>]
abstract member OptString : string * string -> string
override this.OptString : string * string -> string

Parameters

name
String

The name of the value to read, or null if no name is supplied.

fallback
String

The string to return if the mapping is missing.

Returns

The mapped value converted to a string, or fallback if the mapping is missing. Null converts to "null", not the fallback.

Attributes

Remarks

Returns the value mapped by name if it exists, coercing it if necessary, or fallback if no such mapping exists.

Java documentation for org.json.JSONObject.optString(java.lang.String, java.lang.String).

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