mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-09 15:44:42 +02:00
Updated Examples (markdown)
19
Examples.md
19
Examples.md
@@ -71,6 +71,8 @@ getting the data on JSON format and parsing the buffer:
|
||||
|
||||
## Example 3: iterators
|
||||
|
||||
### JsonArray
|
||||
|
||||
```c++
|
||||
char json[] = "[\"A\",\"B\",\"C\"]";
|
||||
JsonArray& array = jsonBuffer.parseArray(json);
|
||||
@@ -85,6 +87,7 @@ for(JsonArray::iterator it=array.begin(); it!=array.end(); ++it)
|
||||
|
||||
}
|
||||
```
|
||||
### JsonObject
|
||||
|
||||
```c++
|
||||
char json[] = "{\"key\":\"value\"}";
|
||||
@@ -104,6 +107,22 @@ for(JsonObject::iterator it=object.begin(); it!=object.end(); ++it)
|
||||
}
|
||||
```
|
||||
|
||||
### JsonVariant
|
||||
|
||||
for an object:
|
||||
```c++
|
||||
for( const auto& kv : variant.as<JsonObject>() ) {
|
||||
Serial.println(kv.key);
|
||||
Serial.println(kv.value.as<char*>());
|
||||
}
|
||||
```
|
||||
and for an array:
|
||||
```c++
|
||||
for( const auto& value : variant.as<JsonArray>() ) {
|
||||
Serial.println(value.as<char*>());
|
||||
}
|
||||
```
|
||||
|
||||
## Example 4: Serialize and Deserialize
|
||||
Here is the canonical example for serializing and deserializing with ArduinoJson.
|
||||
By following this example, you are making the best usage of your memory and you maintain a good software design.
|
||||
|
Reference in New Issue
Block a user