From 607210b6aeadc4d594a570f52dc21ba9e5cd5762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Tue, 19 Jan 2016 10:10:28 +0100 Subject: [PATCH] Updated FAQ (markdown) --- FAQ.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/FAQ.md b/FAQ.md index 375315e..943f180 100644 --- a/FAQ.md +++ b/FAQ.md @@ -9,6 +9,17 @@ No. This is a fundamental design principle in this library. The JSON input must be in memory and must be mutable (ie not readonly) to allow zero-copy and zero-allocation, which is *the* strength of this library. +Let's see an example to understand why this is important: + +```c++ +char json[] = "{\"hello\":\"world\"}"; +JsonObject& root = jsonBuffer.parseObject(json); +const char* world = root["hello"]; +``` + +After executing the lines above, the variable `world` will point to the word `"world"` inside the `json` string. During the call to `parseObject()`, the `json` string has been modified to insert the necessary zero-terminator (`\0`), to cut the string `world`. +As you can see this process requires neither duplication nor allocation, but imposes the input to be stored in a `char[]`. + To parse data from a stream, you'll have to read its content and put it in a `char[]`: ```c++