From 85cb0f44c4c7297a75141999674f3eb0fdf6a308 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 16 Oct 2007 17:25:08 +0100 Subject: Add a method for getting all the nodes from a JsonObject To map json_array_get_elements(), a json_object_get_values() method has been added which returns the list of JsonNodes contained by a JsonObject. --- json-glib/json-object.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'json-glib/json-object.c') diff --git a/json-glib/json-object.c b/json-glib/json-object.c index 32a6a85..c6eeff1 100644 --- a/json-glib/json-object.c +++ b/json-glib/json-object.c @@ -179,6 +179,16 @@ get_keys (gpointer key, *keys = g_list_prepend (*keys, key); } +static void +get_values (gpointer key, + gpointer value, + gpointer user_data) +{ + GList **values = user_data; + + *values = g_list_prepend (*values, value); +} + static GList * g_hash_table_get_keys (GHashTable *hash_table) { @@ -190,6 +200,18 @@ g_hash_table_get_keys (GHashTable *hash_table) return retval; } + +static GList * +g_hash_table_get_values (GHashTable *hash_table) +{ + GList *retval = NULL; + + g_return_val_if_fail (hash_table != NULL, NULL); + + g_hash_table_foreach (hash_table, get_values, &retval); + + return retval; +} #endif /* GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14 */ /** @@ -212,6 +234,25 @@ json_object_get_members (JsonObject *object) return g_hash_table_get_keys (object->members); } +/** + * json_object_get_values: + * @object: a #JsonObject + * + * Retrieves all the values of the members of a #JsonObject. + * + * Return value: 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. + */ +GList * +json_object_get_values (JsonObject *object) +{ + g_return_val_if_fail (object != NULL, NULL); + + return g_hash_table_get_values (object->members); +} + /** * json_object_get_member: * @object: a #JsonObject -- cgit v1.2.1