json: simplify JSON_VARIANT_OBJECT_FOREACH() macro a bit

There's no point in returning the "key" within each loop iteration as
JsonVariant object. Let's simplify things and return it as string. That
simplifies usage (since the caller doesn't have to convert the object to
the string anymore) and is safe since we already validate that keys are
strings when an object JsonVariant is allocated.
This commit is contained in:
Lennart Poettering
2019-04-12 13:11:11 +02:00
parent 15de23a0b2
commit 33d60b8d57
2 changed files with 12 additions and 14 deletions
+1 -1
View File
@@ -143,7 +143,7 @@ struct json_variant_foreach_state {
#define JSON_VARIANT_OBJECT_FOREACH(k, e, v) \
for (struct json_variant_foreach_state _state = { (v), 0 }; \
_state.idx < json_variant_elements(_state.variant) && \
({ k = json_variant_by_index(_state.variant, _state.idx); \
({ k = json_variant_string(json_variant_by_index(_state.variant, _state.idx)); \
e = json_variant_by_index(_state.variant, _state.idx + 1); \
true; }); \
_state.idx += 2)