From 6418605bd9a983a0997aa765c4ccb5952a0160ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Mon, 29 Aug 2016 19:10:45 +0200 Subject: [PATCH] Updated FAQ (markdown) --- FAQ.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/FAQ.md b/FAQ.md index 79f9076..9865732 100644 --- a/FAQ.md +++ b/FAQ.md @@ -10,6 +10,7 @@ * [How to reuse a `JsonBuffer`?](#how-to-reuse-a-jsonbuffer) * [What's the best way to use the library?](#whats-the-best-way-to-use-the-library) * [How to write a function that works with both `JsonArray` and `JsonObject`?](#how-to-write-a-function-that-works-with-both-jsonarray-and-jsonobject) + * [How to assign a `JsonArray` or `JsonObject`?](#how-to-assign-a-jsonarray-or-jsonobject) * [Part 2 - Serialization questions](#part-2---serialization-questions) * [How to compute the JSON length?](#how-to-compute-the-json-length) * [How to create complex nested objects?](#how-to-create-complex-nested-objects) @@ -294,7 +295,30 @@ void myFunction(JsonVariant variant) See issue [#195](https://github.com/bblanchon/ArduinoJson/issues/195) and [#196](https://github.com/bblanchon/ArduinoJson/issues/196) +### How to assign a `JsonArray` or `JsonObject`? +If you try to reassign a `JsonArray&` or a `JsonObject&`, you'll have the following error: + +``` +error: use of deleted function 'ArduinoJson::JsonArray& ArduinoJson::JsonArray::operator=(const ArduinoJson::JsonArray&)' +error: use of deleted function 'ArduinoJson::JsonObject& ArduinoJson::JsonObject::operator=(const ArduinoJson::JsonObject&)' +``` + +Indeed, you cannot reassign a `JsonObject&`. + +One solution is to use a pointer instead. + +```c++ +JsonObject* myObject = &root["myObject"].as(); +``` + +You can also use a `JsonVariant` which will act as a wrapper around the pointer. + +```c++ +JsonVariant myObject = root["myObject"]; +``` + +See issues [#341](https://github.com/bblanchon/ArduinoJson/issues/341) and [#343](https://github.com/bblanchon/ArduinoJson/issues/343). ## Part 2 - Serialization questions