From cf2eceeb69ccbda4f2ff583ee7869c7fd3cda603 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 21 Nov 2007 20:41:42 +0000 Subject: Add API to retrieve copies of the nodes inside objects and arrays Getting copies of the nodes might work better for high level languages binding the JSON-GLib API, because they can manage the lifetime of the returned values using their own rules. --- json-glib/json-object.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'json-glib/json-object.c') diff --git a/json-glib/json-object.c b/json-glib/json-object.c index c6eeff1..e0b4181 100644 --- a/json-glib/json-object.c +++ b/json-glib/json-object.c @@ -253,6 +253,35 @@ json_object_get_values (JsonObject *object) return g_hash_table_get_values (object->members); } +/** + * json_object_dup_member: + * @object: a #JsonObject + * @member_name: the name of the JSON object member to access + * + * Retrieves a copy of the #JsonNode containing the value of @member_name + * inside a #JsonObject + * + * Return value: a copy of the node for the requested object member + * or %NULL. Use json_node_free() when done. + * + * Since: 0.6 + */ +JsonNode * +json_object_dup_member (JsonObject *object, + const gchar *member_name) +{ + JsonNode *retval; + + g_return_val_if_fail (object != NULL, NULL); + g_return_val_if_fail (member_name != NULL, NULL); + + retval = json_object_get_member (object, member_name); + if (!retval) + return NULL; + + return json_node_copy (retval); +} + /** * json_object_get_member: * @object: a #JsonObject -- cgit v1.2.1