diff --git a/FAQ.md b/FAQ.md index 65b1b1d..d8ed2ef 100644 --- a/FAQ.md +++ b/FAQ.md @@ -20,6 +20,7 @@ * [The first parsing succeeds, why do the next ones fail?](#the-first-parsing-succeeds-why-do-the-next-ones-fail) * [Parsing succeeds but I can't read the values!](#parsing-succeeds-but-i-cant-read-the-values) * [How to know the type of a value?](#how-to-know-the-type-of-a-value) + * [Can I access to object member by its index, instead of its key?](#can-i-access-to-object-member-by-its-index-instead-of-its-key) * [How to fix error "Ambiguous overload for 'operator='"](#how-to-fix-error-ambiguous-overload-for-operator) @@ -654,6 +655,33 @@ array[0].is(); // return false See issues [#148](https://github.com/bblanchon/ArduinoJson/issues/148), [#175](https://github.com/bblanchon/ArduinoJson/issues/175) and [#213](https://github.com/bblanchon/ArduinoJson/issues/213). +### Can I access to object member by its index, instead of its key? + +No. + +But you can enumerate all the key-value pairs in the object, by using iterators: + +```c++ +char json[] = "{\"key\":\"value\"}"; +JsonObject& object = jsonBuffer.parseObject(json); + +for(JsonObject::iterator it=object.begin(); it!=object.end(); ++it) +{ + const char* key = it->key; + + if (it->value.is()) { + const char* value = it->value; + // ... + } + + if (it->value.is()) { + JsonObject& value = it->value; + // you can recursively traverse objects... + } +} +``` + +See issue [#278](https://github.com/bblanchon/ArduinoJson/issues/278). ### How to fix error "Ambiguous overload for 'operator='"