From 6e3168e7f24fac4d0e49c2ca768c5eb97b4d1539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Thu, 29 Sep 2016 11:39:44 +0200 Subject: [PATCH] Updated FAQ (markdown) --- FAQ.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/FAQ.md b/FAQ.md index a8e8c97..3ec618e 100644 --- a/FAQ.md +++ b/FAQ.md @@ -13,6 +13,7 @@ - [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) + - [Why some parts are missing?](#why-some-parts-are-missing) - [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) @@ -182,7 +183,7 @@ See issues [#160](https://github.com/bblanchon/ArduinoJson/issues/160), [#203](h ### How to reuse a `JsonBuffer`? -`StaticJsonBuffer` and `DynamicJsonBuffer` are designed to be throwaway memory pools, they are not intended to be reused. +`StaticJsonBuffer` and `DynamicJsonBuffer` are designed to be throwaway memory pools, they are not intended to be reused. As a consequence, using a global `JsonBuffer` is almost always a bad idea. If you believe you need to reuse a `JsonBuffer`, it's because [you're not using the library correctly](https://github.com/bblanchon/ArduinoJson/wiki/FAQ#whats-the-best-way-to-use-the-library). @@ -193,7 +194,7 @@ Imagine a `clear()` function is available, someone could write: ```c++ JsonObject& myObject = jsonBuffer.createObject(); -jsonBuffer.clear(); +jsonBuffer.clear(); JsonArray& myArray = jsonBuffer.createArray(); ``` @@ -292,7 +293,7 @@ void myFunction(JsonVariant variant) JsonArray& array = variant; // ... } - else if (variant.is()) + else if (variant.is()) { JsonObject& object = variant; // ... @@ -336,6 +337,21 @@ See issues [#341](https://github.com/bblanchon/ArduinoJson/issues/341) and [#343 ## Part 2 - Serialization questions +### Why some parts are missing? + +Example: you want to write `{"p1":[0, 1]}`, but instead you get `{"p1":[]}`. + +This is because the `StaticJsonBuffer` too small. + +Solution: Increase the size of the `StaticJsonBuffer` or switch to a `DynamicJsonBuffer`. + +See also: + +* [What are the differences between StaticJsonBuffer and DynamicJsonBuffer?](#what-are-the-differences-between-staticjsonbuffer-and-dynamicjsonbuffer) +* [How to determine the buffer size?](#how-to-determine-the-buffer-size) +* [JsonBuffer size calculator](https://rawgit.com/bblanchon/ArduinoJson/master/scripts/buffer-size-calculator.html) +* Issue [#360](https://github.com/bblanchon/ArduinoJson/issues/360) + ### How to compute the JSON length? @@ -731,11 +747,11 @@ But you can enumerate all the key-value pairs in the object, by using iterators: char json[] = "{\"key\":\"value\"}"; JsonObject& object = jsonBuffer.parseObject(json); -for(JsonObject::iterator it=object.begin(); it!=object.end(); ++it) +for(JsonObject::iterator it=object.begin(); it!=object.end(); ++it) { const char* key = it->key; - if (it->value.is()) { + if (it->value.is()) { const char* value = it->value; // ... } @@ -776,4 +792,4 @@ ssid = network["ssid"].as(); ssid = network["ssid"].as(); ``` -See issue [#118](https://github.com/bblanchon/ArduinoJson/issues/118), [#146](https://github.com/bblanchon/ArduinoJson/issues/146) and [#197](https://github.com/bblanchon/ArduinoJson/issues/197). \ No newline at end of file +See issue [#118](https://github.com/bblanchon/ArduinoJson/issues/118), [#146](https://github.com/bblanchon/ArduinoJson/issues/146) and [#197](https://github.com/bblanchon/ArduinoJson/issues/197).