diff --git a/API-Reference.md b/API-Reference.md index bbb8236..2e53337 100644 --- a/API-Reference.md +++ b/API-Reference.md @@ -737,12 +737,59 @@ JsonObject& object2 = jsonBuffer.parseObject(json); ``` +### JsonObject::begin() / JsonObject::end() + +##### Description +Returns an iterator that can be use to get all key-value pairs in the object. + +##### Signatures + +```c++ +JsonObject::iterator begin(); +JsonObject::iterator end(); +JsonObject::const_iterator begin() const; +JsonObject::const_iterator end() const; +``` + +##### Return value +A forward iterator pointing to a `JsonPair`, which itself contains two members `key` and `value`. + +##### Example + +```c++ +char json[] = "{\"first\":\"hello\",\"second\":\"world\"}"; +DynamicJsonBuffer jsonBuffer; +JsonObject& root = jsonBuffer.parseObject(json); + +// using C++98 syntax: +for (JsonObject::iterator it=root.begin(); it!=root.end(); ++it) { + Serial.println(it->key); + Serial.println(it->value); +} + +// using C++11 syntax: +for (auto kv : root) { + Serial.println(kv.key); + Serial.println(kv.value); +} +``` + +The code above would print: + +``` +first +hello +second +world +``` + + ### JsonObject::createNestedArray() ##### Description Creates a `JsonArray` as a child of the current object. -##### Signature +##### Signatures ```c++ JsonArray& createNestedArray(const char* key) const; @@ -782,8 +829,8 @@ will print { "status": "on", "levels": [ - 10, - 20 + 10, + 20 ] } ``` @@ -834,8 +881,8 @@ will print { "city": "Paris", "weather": { - "temp": 14.20, - "cond": "cloudy" + "temp": 14.20, + "cond": "cloudy" } } ```