Updated FAQ (markdown)

Benoît Blanchon
2016-10-28 14:15:32 +02:00
parent 5d20b853f6
commit e7659923da

33
FAQ.md

@@ -20,6 +20,7 @@
- [The first serialization succeeds, why do the next ones fail?](#the-first-serialization-succeeds-why-do-the-next-ones-fail)
- [Why ArduinoJson is slow?](#why-arduinojson-is-slow)
- [Part 3 - Deserialization/parsing questions](#part-3---deserializationparsing-questions)
- [Why do I have a segmentation fault?](#why-do-i-have-a-segmentation-fault)
- [Can I parse data from a stream?](#can-i-parse-data-from-a-stream)
- [Can I parse a JSON input that is too big to fit in memory?](#can-i-parse-a-json-input-that-is-too-big-to-fit-in-memory)
- [Should I call `parseArray\(\)` or `parseObject\(\)`?](#should-i-call-parsearray-or-parseobject)
@@ -478,6 +479,38 @@ See issue [#166](https://github.com/bblanchon/ArduinoJson/issues/166), [#271](ht
## Part 3 - Deserialization/parsing questions
### Why do I have a segmentation fault?
`parseArray()` and `parseObject()` may cause a segmentation fault if the input string is in a read-only segment.
Indeed, the parser modifies the string for two reasons:
1. it inserts `\0` to terminate substrings,
2. it translate escaped characters like `\n` or `\t`.
Most of the time this wont be an issue, but there are some corner cases that can be problematic.
Let take the example bellow:
char[] json = "[\"hello\",\"world\"]";
StaticJsonBuffer<32> buffer;
JsonArray& array = buffer.parseArray(json);
If you replace it by:
char* json = "[\"hello\",\"world\"]";
StaticJsonBuffer<32> buffer;
JsonArray& array = buffer.parseArray(json);
Depending on your platform, you may have an exception because the parser tries to write at a location that is read-only.
In the first case `char json[]` declares an array of `char` initialized to the specified string.
In the second case `char* json` declares a pointer to a read-only string, in fact it should be a `const char*` instead of a `char*`.
See:
* issue [#378](https://github.com/bblanchon/ArduinoJson/issues/378)
* [Avoiding pitfalls: Make sure the string isn't read-only](https://github.com/bblanchon/ArduinoJson/wiki/Avoiding%20pitfalls#7-make-sure-the-string-isnt-read-only)
### Can I parse data from a stream?
### Can I parse a JSON input that is too big to fit in memory?