Added JsonObject iterator

Benoît Blanchon
2015-09-01 08:31:22 +02:00
parent ad14662169
commit ad23bca797

@@ -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<const char*>());
// this also works:
value = it->as<const char*>();
}
```
```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<const char*>();
}
```