mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-16 02:51:14 +02:00
Added JsonObject iterator
33
Examples.md
33
Examples.md
@@ -54,16 +54,35 @@ getting the data on JSON format and parsing the buffer:
|
|||||||
MET->MTwindspeed = _ooo ["windSpeed"]; // speed
|
MET->MTwindspeed = _ooo ["windSpeed"]; // speed
|
||||||
MET->MTobservationtime= _ooo ["datetime"]; // time
|
MET->MTobservationtime= _ooo ["datetime"]; // time
|
||||||
|
|
||||||
## Example 3: use iterators
|
## Example 3: iterators
|
||||||
|
|
||||||
|
|
||||||
```c++
|
```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;
|
const char* value = *it;
|
||||||
Serial.println(value);
|
|
||||||
// or
|
// this also works:
|
||||||
Serial.println(it->as<const char*>());
|
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*>();
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
Reference in New Issue
Block a user