JsonObject Class
- java.
lang. Object - com.
azure. json. models. JsonElement - com.
azure. json. models. JsonObject
- com.
- com.
public final class JsonObject
extends JsonElement
Class representing the JSON object type.
Constructor Summary
| Constructor | Description |
|---|---|
| JsonObject() |
Default constructor. |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
|
static
Json |
fromJson(JsonReader jsonReader)
Deserializes a JSON object from a Json |
|
Json |
getProperty(String key)
Gets the Json |
| boolean |
hasProperty(String key)
Checks whether a property with the specified key exists in the JSON object. |
| boolean |
isObject()
Indicates whether the element is an object. |
|
Json |
removeProperty(String key)
Removes the Json |
|
Json |
setProperty(String key, boolean element)
Sets the boolean value corresponding to the specified key. |
|
Json |
setProperty(String key, JsonElement element)
Sets the Json |
|
Json |
setProperty(String key, Number element)
Sets the number value corresponding to the specified key. |
|
Json |
setProperty(String key, String element)
Sets the string value corresponding to the specified key. |
| int |
size()
The number of properties in the JSON object. |
|
Json |
toJson(JsonWriter jsonWriter) |
| String | toJsonString() |
Methods inherited from JsonElement
Methods inherited from java.lang.Object
Constructor Details
JsonObject
public JsonObject()
Default constructor.
Method Details
fromJson
public static JsonObject fromJson(JsonReader jsonReader)
Deserializes a JSON object from a JsonReader.
If the JsonReader's current token is null, it is assumed the JsonReader hasn't begun reading and nextToken() will be called to begin reading.
After ensuring the JsonReader has begun reading, if the current token is not START_OBJECT, an IllegalStateException will be thrown. Otherwise, a JSON object representing the object will be created and returned.
Parameters:
Returns:
Throws:
getProperty
public JsonElement getProperty(String key)
Gets the JsonElement value corresponding to the specified key. If the key doesn't exist, null will be returned.
Parameters:
Returns:
hasProperty
public boolean hasProperty(String key)
Checks whether a property with the specified key exists in the JSON object.
Parameters:
Returns:
isObject
public boolean isObject()
Indicates whether the element is an object.
Overrides:
JsonObject.isObject()removeProperty
public JsonElement removeProperty(String key)
Removes the JsonElement value corresponding to the specified key. If the key doesn't exist, null will be returned.
Parameters:
Returns:
setProperty
public JsonObject setProperty(String key, boolean element)
Sets the boolean value corresponding to the specified key. If the key already exists, the value will be overwritten.
Parameters:
Returns:
setProperty
public JsonObject setProperty(String key, JsonElement element)
Sets the JsonElement value corresponding to the specified key. If the key already exists, the value will be overwritten.
Parameters:
Returns:
setProperty
public JsonObject setProperty(String key, Number element)
Sets the number value corresponding to the specified key. If the key already exists, the value will be overwritten.
If element is null this will set the property to JsonNull.
Parameters:
Returns:
setProperty
public JsonObject setProperty(String key, String element)
Sets the string value corresponding to the specified key. If the key already exists, the value will be overwritten.
If element is null this will set the property to JsonNull.
Parameters:
Returns:
size
public int size()
The number of properties in the JSON object.
Returns: