From d75b04c1bc9934c8a75fb1bfc2a2de1fecc2aa60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Wed, 13 Jan 2016 21:04:31 +0100 Subject: [PATCH] Updated FAQ (markdown) --- FAQ.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/FAQ.md b/FAQ.md index f3ccd99..d6bc808 100644 --- a/FAQ.md +++ b/FAQ.md @@ -260,6 +260,25 @@ array[0].is(); // 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`