diff --git a/Examples.md b/Examples.md index 121a222..efde24e 100644 --- a/Examples.md +++ b/Examples.md @@ -54,16 +54,35 @@ getting the data on JSON format and parsing the buffer: MET->MTwindspeed = _ooo ["windSpeed"]; // speed MET->MTobservationtime= _ooo ["datetime"]; // time -## Example 3: use iterators - +## Example 3: iterators ```c++ -JsonArray & array; +JsonArray& array; -for(JsonArray::iterator it=array.begin(); it!=array.end(); ++it) { +for(JsonArray::iterator it=array.begin(); it!=array.end(); ++it) +{ + // *it contains the JsonVariant which can be casted as usuals const char* value = *it; - Serial.println(value); - // or - Serial.println(it->as()); + + // this also works: + value = it->as(); + +} +``` + +```c++ +JsonObject& object; + +for(JsonObject::iterator it=object.begin(); it!=object.end(); ++it) +{ + // *it contains the key/value pair + const char* key = it->key; + + // it->value contains the JsonVariant which can be casted as usual + const char* value = it->value; + + // this also works + value = it->value.as(); + } ``` \ No newline at end of file