How to iterate over a JsonVariant
?
There is no iterator on JsonVariant
because it would be ambiguous.
Before iterating on a variant, the program must cast it to either a JsonArray
or JsonObject
.
For instance, for an object:
for( const auto& kv : variant.as<JsonObject>() ) {
Serial.println(kv.key);
Serial.println(kv.value.as<char*>());
}
and for an array:
for( const auto& value : variant.as<JsonArray>() ) {
Serial.println(value.as<char*>());
}
See: