Updated FAQ (markdown)

Benoît Blanchon
2016-04-28 08:26:31 +02:00
parent e278e4f895
commit 84b98c362a

29
FAQ.md

@@ -10,7 +10,8 @@
* [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)
* [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)
* [Part 3 - Deserialization questions](#part-3---deserializationparsing-questions)
* [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 array, call `createNestedArray()`.