diff options
| author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-10-16 17:25:08 +0100 | 
|---|---|---|
| committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-10-16 17:25:08 +0100 | 
| commit | 85cb0f44c4c7297a75141999674f3eb0fdf6a308 (patch) | |
| tree | 8d3d81f7ac0e0be156bcf729f95519be7586f51e /json-glib/json-object.c | |
| parent | 474ecf1cc6aae35b184edffc75fc8626c3f12f61 (diff) | |
| download | json-glib-85cb0f44c4c7297a75141999674f3eb0fdf6a308.tar.gz | |
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.
Diffstat (limited to 'json-glib/json-object.c')
| -rw-r--r-- | json-glib/json-object.c | 41 | 
1 files changed, 41 insertions, 0 deletions
| 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 */  /** @@ -213,6 +235,25 @@ json_object_get_members (JsonObject *object)  }  /** + * json_object_get_values: + * @object: a #JsonObject + * + * Retrieves all the values of the members of a #JsonObject. + * + * Return value: a #GList of #JsonNode<!-- -->s. 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   * @member_name: the name of the JSON object member to access | 
