Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gson
Class JsonObject

    java.lang.Object
      com.google.gson.JsonElement
          com.google.gson.JsonObject

    public final class JsonObject

extends JsonElement

A class representing an object type in Json. An object consists of name-value pairs where names are strings, and values are any other type of `JsonElement`. This allows for a creating a tree of JsonElements. The member elements of this object are maintained in order they were added.

Author:
  Inderjeet Singh, Joel Leitch

Constructor Summary
`JsonObject()`

Method Summary
`void` | `add(String property, JsonElement value)` Adds a member, which is a name-value pair, to self.
`void` | `addProperty(String property, Boolean value)` Convenience method to add a boolean member.
`void` | `addProperty(String property, Character value)` Convenience method to add a char member.
`void` | `addProperty(String property, Number value)` Convenience method to add a primitive member.
`void` | `addProperty(String property, String value)` Convenience method to add a primitive member.
`Set<Map.Entry<String,JsonElement>>` | `entrySet()` Returns a set of members of this object.
`boolean` | `equals(Object o)`
`JsonElement` | `get(String memberName)` Returns the member with the specified name.
`JsonArray` | `getAsJsonArray(String memberName)` Convenience method to get the specified member as a JsonArray.
`JsonObject` | `getAsJsonObject(String memberName)` Convenience method to get the specified member as a JsonObject.
`JsonPrimitive` | `getAsJsonPrimitive(String memberName)` Convenience method to get the specified member as a JsonPrimitive element.
`boolean` | `has(String memberName)` Convenience method to check if a member with the specified name is present in this object.
`int` | `hashCode()`
`JsonElement` | `remove(String property)` Removes the `property` from this `JsonObject`.

Methods inherited from class com.google.gson.JsonElement
`getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsCharacter, getAsDouble, getAsFloat, getAsInt, getAsJsonArray, getAsJsonNull, getAsJsonObject, getAsJsonPrimitive, getAsLong, getAsNumber, getAsShort, getAsString, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### JsonObject

    public JsonObject()

Method Detail

### add

    public void add(String property,
                    JsonElement value)

  Adds a member, which is a name-value pair, to self. The name must be a String, but the value can be an arbitrary JsonElement, thereby allowing you to build a full tree of JsonElements rooted at this node.

  Parameters:
    `property` - name of the member.
    `value` - the member object.

### remove

    public JsonElement remove(String property)

  Removes the `property` from this `JsonObject`.

  Parameters:
    `property` - name of the member that should be removed.
  Returns:
    the `JsonElement` object that is being removed.
  Since:
    1.3

### addProperty

    public void addProperty(String property,
                            String value)

  Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of String.

  Parameters:
    `property` - name of the member.
    `value` - the string value associated with the member.

### addProperty

    public void addProperty(String property,
                            Number value)

  Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of Number.

  Parameters:
    `property` - name of the member.
    `value` - the number value associated with the member.

### addProperty

    public void addProperty(String property,
                            Boolean value)

  Convenience method to add a boolean member. The specified value is converted to a JsonPrimitive of Boolean.

  Parameters:
    `property` - name of the member.
    `value` - the number value associated with the member.

### addProperty

    public void addProperty(String property,
                            Character value)

  Convenience method to add a char member. The specified value is converted to a JsonPrimitive of Character.

  Parameters:
    `property` - name of the member.
    `value` - the number value associated with the member.

### entrySet

    public Set<Map.Entry<String,JsonElement>> entrySet()

  Returns a set of members of this object. The set is ordered, and the order is in which the elements were added.

  Returns:
    a set of members of this object.

### has

    public boolean has(String memberName)

  Convenience method to check if a member with the specified name is present in this object.

  Parameters:
    `memberName` - name of the member that is being checked for presence.
  Returns:
    true if there is a member with the specified name, false otherwise.

### get

    public JsonElement get(String memberName)

  Returns the member with the specified name.

  Parameters:
    `memberName` - name of the member that is being requested.
  Returns:
    the member matching the name. Null if no such member exists.

### getAsJsonPrimitive

    public JsonPrimitive getAsJsonPrimitive(String memberName)

  Convenience method to get the specified member as a JsonPrimitive element.

  Parameters:
    `memberName` - name of the member being requested.
  Returns:
    the JsonPrimitive corresponding to the specified member.

### getAsJsonArray

    public JsonArray getAsJsonArray(String memberName)

  Convenience method to get the specified member as a JsonArray.

  Parameters:
    `memberName` - name of the member being requested.
  Returns:
    the JsonArray corresponding to the specified member.

### getAsJsonObject

    public JsonObject getAsJsonObject(String memberName)

  Convenience method to get the specified member as a JsonObject.

  Parameters:
    `memberName` - name of the member being requested.
  Returns:
    the JsonObject corresponding to the specified member.

### equals

    public boolean equals(Object o)

  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008–2014 Google, Inc.. All rights reserved.