mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-03 12:44:50 +02:00
Updated FAQ (markdown)
24
FAQ.md
24
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<JsonObject>();
|
||||
```
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user