mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-18 03:51:21 +02:00
Updated FAQ (markdown)
11
FAQ.md
11
FAQ.md
@@ -9,6 +9,17 @@ No.
|
|||||||
This is a fundamental design principle in this library.
|
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.
|
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[]`:
|
To parse data from a stream, you'll have to read its content and put it in a `char[]`:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
Reference in New Issue
Block a user