aboutsummaryrefslogtreecommitdiff
path: root/src/value.c
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2009-04-30 16:38:22 +0300
committerPetri Lehtinen <petri@digip.org>2009-05-12 21:44:45 +0300
commita2adf6ec98bb45a3152e5006606a3d511e7b77a0 (patch)
treeccfddb1be4a1beb0566dda2d13aa7d9ca7f7663f /src/value.c
parent17a69c2d66a86757877c3d4159e999da3a5434bf (diff)
downloadjansson-a2adf6ec98bb45a3152e5006606a3d511e7b77a0.zip
jansson-a2adf6ec98bb45a3152e5006606a3d511e7b77a0.tar.gz
jansson-a2adf6ec98bb45a3152e5006606a3d511e7b77a0.tar.bz2
Add support for iterating over objects
Diffstat (limited to 'src/value.c')
-rw-r--r--src/value.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/value.c b/src/value.c
index 6ab44a6..d330203 100644
--- a/src/value.c
+++ b/src/value.c
@@ -104,6 +104,17 @@ json_t *json_object_get(const json_t *json, const char *key)
return hashtable_get(object->hashtable, key);
}
+int json_object_set(json_t *json, const char *key, json_t *value)
+{
+ json_object_t *object;
+
+ if(!json_is_object(json))
+ return -1;
+
+ object = json_to_object(json);
+ return hashtable_set(object->hashtable, strdup(key), json_incref(value));
+}
+
int json_object_del(json_t *json, const char *key)
{
json_object_t *object;
@@ -115,15 +126,42 @@ int json_object_del(json_t *json, const char *key)
return hashtable_del(object->hashtable, key);
}
-int json_object_set(json_t *json, const char *key, json_t *value)
+void *json_object_iter(json_t *json)
{
json_object_t *object;
if(!json_is_object(json))
- return -1;
+ return NULL;
object = json_to_object(json);
- return hashtable_set(object->hashtable, strdup(key), json_incref(value));
+ return hashtable_iter(object->hashtable);
+}
+
+void *json_object_iter_next(json_t *json, void *iter)
+{
+ json_object_t *object;
+
+ if(!json_is_object(json) || iter == NULL)
+ return NULL;
+
+ object = json_to_object(json);
+ return hashtable_iter_next(object->hashtable, iter);
+}
+
+const char *json_object_iter_key(void *iter)
+{
+ if(!iter)
+ return NULL;
+
+ return (const char *)hashtable_iter_key(iter);
+}
+
+json_t *json_object_iter_value(void *iter)
+{
+ if(!iter)
+ return NULL;
+
+ return (json_t *)hashtable_iter_value(iter);
}