![]() |
![]() |
![]() |
JSON-GLib 0.6.2 Reference Manual | ![]() |
---|---|---|---|---|
JsonObject; JsonObject* json_object_new (void); JsonObject* json_object_ref (JsonObject *object); void json_object_unref (JsonObject *object); void json_object_add_member (JsonObject *object, const gchar *member_name, JsonNode *node); gboolean json_object_has_member (JsonObject *object, const gchar *member_name); JsonNode* json_object_get_member (JsonObject *object, const gchar *member_name); JsonNode* json_object_dup_member (JsonObject *object, const gchar *member_name); GList* json_object_get_members (JsonObject *object); GList* json_object_get_values (JsonObject *object); guint json_object_get_size (JsonObject *object); void json_object_remove_member (JsonObject *object, const gchar *member_name);
JsonArray is the representation of the object type inside JSON. It contains
JsonNodes, which may contain fundamental types, arrays or other
objects. Each member of an object is accessed using its name. Please note
that the member names are normalized internally before being used; every
delimiter matching the G_STR_DELIMITER
macro will be transformed into an
underscore, so for instance "member-name" and "member_name" are equivalent
for a JsonObject.
Since objects can be expensive, they are reference counted. You can control
the lifetime of a JsonObject using json_object_ref()
and json_object_unref()
.
To add a member with a given name, use json_object_add_member()
.
To extract a member with a given name, use json_object_get_member()
.
To retrieve the list of members, use json_object_get_members()
.
To retrieve the size of the object (that is, the number of members it has), use
json_object_get_size()
.
typedef struct _JsonObject JsonObject;
A JSON object type. The contents of the JsonObject structure are private and should only be accessed by the provided API
JsonObject* json_object_new (void);
Creates a new JsonObject, an JSON object type representation.
Returns : |
the newly created JsonObject |
JsonObject* json_object_ref (JsonObject *object);
Increase by one the reference count of a JsonObject.
|
a JsonObject |
Returns : |
the passed JsonObject, with the reference count increased by one. |
void json_object_unref (JsonObject *object);
Decreases by one the reference count of a JsonObject. If the reference count reaches zero, the object is destroyed and all its allocated resources are freed.
|
a JsonObject |
void json_object_add_member (JsonObject *object, const gchar *member_name, JsonNode *node);
Adds a member named member_name
and containing node
into a JsonObject.
The object will take ownership of the JsonNode.
|
a JsonObject |
|
the name of the member |
|
the value of the member |
gboolean json_object_has_member (JsonObject *object, const gchar *member_name);
Checks whether object
has a member named member_name
.
|
a JsonObject |
|
the name of a JSON object member |
Returns : |
TRUE if the JSON object has the requested member
|
JsonNode* json_object_get_member (JsonObject *object, const gchar *member_name);
Retrieves the JsonNode containing the value of member_name
inside
a JsonObject.
|
a JsonObject |
|
the name of the JSON object member to access |
Returns : |
a pointer to the node for the requested object
member, or NULL
|
JsonNode* json_object_dup_member (JsonObject *object, const gchar *member_name);
Retrieves a copy of the JsonNode containing the value of member_name
inside a JsonObject
|
a JsonObject |
|
the name of the JSON object member to access |
Returns : |
a copy of the node for the requested object member
or NULL . Use json_node_free() when done.
|
Since 0.6
GList* json_object_get_members (JsonObject *object);
Retrieves all the names of the members of a JsonObject. You can
obtain the value for each member using json_object_get_member()
.
|
a JsonObject |
Returns : |
a GList of member names. The content of the list
is owned by the JsonObject and should never be modified or
freed. When you have finished using the returned list, use
g_list_free() to free the resources it has allocated.
|
GList* json_object_get_values (JsonObject *object);
Retrieves all the values of the members of a JsonObject.
|
a JsonObject |
Returns : |
a GList of JsonNodes. The content of the
list is owned by the JsonObject and should never be modified
or freed. When you have finished using the returned list, use
g_list_free() to free the resources it has allocated.
|
guint json_object_get_size (JsonObject *object);
Retrieves the number of members of a JsonObject.
|
a JsonObject |
Returns : |
the number of members |
void json_object_remove_member (JsonObject *object, const gchar *member_name);
Removes member_name
from object
, freeing its allocated resources.
|
a JsonObject |
|
the name of the member to remove |