JSON Object Methods
This page lists the methods of a JSON object variable. Methods can be accessed using the dot(.
) operator.
containsKey()
Syntax
jsonobject.containsKey( keyStr )
Description
Returns a boolean value indicating whether the JSON object contains a specified key.
Return type
BOOL
Parameters
Parameter | Description | Data type |
---|---|---|
|
A string. |
|
Example
If we have the following JSON object represented by the variable han
:
{
"name": "Han Solo",
"age": "39",
"occupation": "mercenary"
}
Then:
han.containsKey("name") -> true
han.containsKey("isJedi") -> false
getBool()
Syntax
jsonobject.getBool( keyStr )
Description
Returns the boolean value associated with a specified key. If the key provided is associated with a non-boolean value, the function will raise a runtime error.
Return type
BOOL
Parameters
Parameter | Description | Data type |
---|---|---|
|
The key whose value to return |
|
Example
If we have the following JSON object represented by the variable han
:
{
"name": "Han Solo",
"age": 39,
"occupation": "mercenary",
"isJedi": false
}
Then:
han.getBool("isJedi") -> false
getDouble()
Syntax
jsonobject.getDouble( keyStr )
Description
Returns the double value associated with a specified key. If the key provided is associated with a non-double value, the function will raise a runtime error.
Return type
DOUBLE
Parameters
Parameter | Description | Data type |
---|---|---|
|
The key whose value to return |
|
getInt()
Syntax
jsonobject.getInt( keyStr )
Description
Returns the integer value associated with a specified key. If the key provided is associated with a non-int value, the function will raise a runtime error.
Return type
INT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The key whose value to return |
|
getJsonArray()
Syntax
jsonobject.getJsonArray( keyStr )
Description
Returns the JSON array value associated with a specified key. If the key provided is associated with a value whose type is not JSON array, the function will raise a runtime error.
Return type
JSONARRAY
Parameters
Parameter | Description | Data type |
---|---|---|
|
The key whose value to return |
|
getJsonObject()
Syntax
jsonobject.getJsonObject( keyStr )
Description
Returns the value associated with a specified key. If the key provided is associated with value whose type is not JSON object, the function will raise a runtime error.
Return type
JSONOBJECT
Parameters
Parameter | Description | Data type |
---|---|---|
|
The key whose value to return |
|
getString()
Syntax
jsonobject.getString( keyStr )
Description
Returns the string value associated with a specified key. If the key provided is associated with a non-string value, the function will raise a runtime error.
Return type
STRING
Parameters
Parameter | Description | Data type |
---|---|---|
|
The key whose value to return |
|