mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-13 17:44:49 +02:00
Updated FAQ (markdown)
25
FAQ.md
25
FAQ.md
@@ -2,6 +2,31 @@
|
|||||||
|
|
||||||
See [Compatibility issues](Compatibility issues) first.
|
See [Compatibility issues](Compatibility issues) first.
|
||||||
|
|
||||||
|
### Should I call `parseArray()` or `parseObject()`?
|
||||||
|
|
||||||
|
This is a very common question as people are often confused when the JSON input contains mixed arrays and objects.
|
||||||
|
|
||||||
|
The answer is very simple: it's the type of the root that matters.
|
||||||
|
This means that you just need to look at the first character: it's either a `[`, for an array, or a `{`, for an object.
|
||||||
|
|
||||||
|
For example, if the input is:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"mickey":["mouse"],"donald":["duck"]}
|
||||||
|
```
|
||||||
|
|
||||||
|
then you must call `parseObject()` because the root is an object.
|
||||||
|
|
||||||
|
And, if the input is:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[{"mickey":"mouse","donald":"duck"}]
|
||||||
|
```
|
||||||
|
|
||||||
|
then you must call `parseArray()` because the root is an array.
|
||||||
|
|
||||||
|
Finally, if you cannot know in advance the type of the root, please open an issue. Don't worry this can be implemented very easily, it's just that nobody asked for it.
|
||||||
|
|
||||||
### Why parsing fails?
|
### Why parsing fails?
|
||||||
|
|
||||||
The parsing functions, `parseArray()` and `parseObject()`, may fail for 3 reasons:
|
The parsing functions, `parseArray()` and `parseObject()`, may fail for 3 reasons:
|
||||||
|
Reference in New Issue
Block a user