Updated FAQ (markdown)

Benoît Blanchon
2015-11-30 22:23:57 +01:00
parent 1bc6cf7d7e
commit 20a6261eb1

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: