aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2015-08-26 17:32:55 +0300
committerPetri Lehtinen <petri@digip.org>2015-08-26 17:32:55 +0300
commit4c4f692bd6814e598c9aa538a3c9979cdf05d566 (patch)
tree23ce6dcfa5e465d32c9af5c7edf73855320a419e /src
parentfef27e6d3efa755a75888db1167f34fa80695b9e (diff)
downloadjansson-4c4f692bd6814e598c9aa538a3c9979cdf05d566.zip
jansson-4c4f692bd6814e598c9aa538a3c9979cdf05d566.tar.gz
jansson-4c4f692bd6814e598c9aa538a3c9979cdf05d566.tar.bz2
Add json_object_foreach_safe
Fixes #230.
Diffstat (limited to 'src')
-rw-r--r--src/jansson.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/jansson.h b/src/jansson.h
index b980e8c..6f7fd07 100644
--- a/src/jansson.h
+++ b/src/jansson.h
@@ -152,6 +152,13 @@ int json_object_iter_set_new(json_t *object, void *iter, json_t *value);
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key))))
+#define json_object_foreach_safe(object, n, key, value) \
+ for(key = json_object_iter_key(json_object_iter(object)), \
+ n = json_object_iter_next(object, json_object_key_to_iter(key)); \
+ key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
+ key = json_object_iter_key(n), \
+ n = json_object_iter_next(object, json_object_key_to_iter(key)))
+
#define json_array_foreach(array, index, value) \
for(index = 0; \
index < json_array_size(array) && (value = json_array_get(array, index)); \