mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-03 12:44:50 +02:00
Updated FAQ (markdown)
29
FAQ.md
29
FAQ.md
@@ -10,7 +10,8 @@
|
|||||||
* [What's the best way to use the library?](#whats-the-best-way-to-use-the-library)
|
* [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 write a function that works with both `JsonArray` and `JsonObject`?](#how-to-write-a-function-that-works-with-both-jsonarray-and-jsonobject)
|
||||||
* [Part 2 - Serialization questions](#part-2---serialization-questions)
|
* [Part 2 - Serialization questions](#part-2---serialization-questions)
|
||||||
* [How do I create complex nested objects?](#how-do-i-create-complex-nested-objects)
|
* [How to compute the JSON length?](#how-to-compute-the-JSON-length)
|
||||||
|
* [How to create complex nested objects?](#how-to-create-complex-nested-objects)
|
||||||
* [The first serialization succeeds, why do the next ones fail?](#the-first-serialization-succeeds-why-do-the-next-ones-fail)
|
* [The first serialization succeeds, why do the next ones fail?](#the-first-serialization-succeeds-why-do-the-next-ones-fail)
|
||||||
* [Part 3 - Deserialization questions](#part-3---deserializationparsing-questions)
|
* [Part 3 - Deserialization questions](#part-3---deserializationparsing-questions)
|
||||||
* [Can I parse data from a stream?](#can-i-parse-data-from-a-stream)
|
* [Can I parse data from a stream?](#can-i-parse-data-from-a-stream)
|
||||||
@@ -282,7 +283,31 @@ See issue [#195](https://github.com/bblanchon/ArduinoJson/issues/195) and [#196]
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
### How do I create complex nested objects?
|
### How to compute the JSON length?
|
||||||
|
|
||||||
|
Use `measureLength()` to compute the number of characters that will be printed by `printTo()`.
|
||||||
|
|
||||||
|
Use `measurePrettyLength()` to compute the number of characters that will be printed by `prettyPrintTo()`.
|
||||||
|
|
||||||
|
None of these methods include the zero terminator.
|
||||||
|
So if you need to allocate a buffer, don't forget to add 1 to the size.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
|
JsonObject& root = jsonBuffer.createObject();
|
||||||
|
root["hello"] = world;
|
||||||
|
|
||||||
|
size_t len = root.measureLength(); // returns 17
|
||||||
|
|
||||||
|
size_t size = len+1;
|
||||||
|
char json[size];
|
||||||
|
root.printTo(json, size); // writes {"hello":"world"}
|
||||||
|
```
|
||||||
|
|
||||||
|
See issues [#75](https://github.com/bblanchon/ArduinoJson/issues/75), [#94](https://github.com/bblanchon/ArduinoJson/issues/94), [#166](https://github.com/bblanchon/ArduinoJson/issues/166), [#178](https://github.com/bblanchon/ArduinoJson/issues/178) and [#268](https://github.com/bblanchon/ArduinoJson/issues/268).
|
||||||
|
|
||||||
|
|
||||||
|
### How to create complex nested objects?
|
||||||
|
|
||||||
To create a nested object, call `createNestedObject()`.
|
To create a nested object, call `createNestedObject()`.
|
||||||
To create a nested array, call `createNestedArray()`.
|
To create a nested array, call `createNestedArray()`.
|
||||||
|
Reference in New Issue
Block a user