mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-23 22:41:13 +02:00
Updated FAQ (markdown)
19
FAQ.md
19
FAQ.md
@@ -260,6 +260,25 @@ array[0].is<JsonObject&>(); // return false
|
||||
|
||||
See issues [#148](https://github.com/bblanchon/ArduinoJson/issues/148) and [#175](https://github.com/bblanchon/ArduinoJson/issues/175).
|
||||
|
||||
### How to write a function that works with both `JsonArray` and `JsonObject`?
|
||||
|
||||
There is no base class for `JsonArray` and `JsonObject`.
|
||||
(Back in version 3.0, they used to derive from `Printable`, but this inheritance has been removed to reduce the memory footprint.)
|
||||
|
||||
However, both `JsonArray` and `JsonObject` can be "stored" in a `JsonVariant`. (I put "stored" in quotes because the `JsonVariant` only contains a reference, not a copy.)
|
||||
|
||||
So here is your function:
|
||||
|
||||
```c++
|
||||
void sendJson(JsonVariant json) {
|
||||
char buffer[512];
|
||||
json.printTo(buffer, sizeof(buffer));
|
||||
g_server.send(200, "application/json", buffer);
|
||||
}
|
||||
```
|
||||
|
||||
See issue [#195](https://github.com/bblanchon/ArduinoJson/issues/195)
|
||||
|
||||
### What are the differences between `StaticJsonBuffer` and `DynamicJsonBuffer`?
|
||||
|
||||
| `StaticJsonBuffer` | `DynamicJsonBuffer`
|
||||
|
Reference in New Issue
Block a user