mirror of
https://github.com/nlohmann/json.git
synced 2026-02-27 22:06:25 +00:00
Merge branch 'develop' of https://github.com/nlohmann/json into bon8
This commit is contained in:
@@ -33,7 +33,7 @@ const_reference operator[](const json_pointer& ptr) const;
|
||||
: index of the element to access
|
||||
|
||||
`key` (in)
|
||||
: object key of the elements to remove
|
||||
: object key of the element to access
|
||||
|
||||
`ptr` (in)
|
||||
: JSON pointer to the desired element
|
||||
@@ -48,10 +48,10 @@ const_reference operator[](const json_pointer& ptr) const;
|
||||
|
||||
1. The function can throw the following exceptions:
|
||||
- Throws [`type_error.305`](../../home/exceptions.md#jsonexceptiontype_error305) if the JSON value is not an array
|
||||
or null; in that cases, using the `[]` operator with an index makes no sense.
|
||||
or null; in that case, using the `[]` operator with an index makes no sense.
|
||||
2. The function can throw the following exceptions:
|
||||
- Throws [`type_error.305`](../../home/exceptions.md#jsonexceptiontype_error305) if the JSON value is not an array
|
||||
or null; in that cases, using the `[]` operator with an index makes no sense.
|
||||
- Throws [`type_error.305`](../../home/exceptions.md#jsonexceptiontype_error305) if the JSON value is not an object
|
||||
or null; in that case, using the `[]` operator with a key makes no sense.
|
||||
3. The function can throw the following exceptions:
|
||||
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index in the passed
|
||||
JSON pointer `ptr` begins with '0'.
|
||||
|
||||
@@ -19,7 +19,7 @@ static basic_json parse(IteratorType first, IteratorType last,
|
||||
1. Deserialize from a compatible input.
|
||||
2. Deserialize from a pair of character iterators
|
||||
|
||||
The value_type of the iterator must be a integral type with size of 1, 2 or 4 bytes, which will be interpreted
|
||||
The `value_type` of the iterator must be an integral type with size of 1, 2 or 4 bytes, which will be interpreted
|
||||
respectively as UTF-8, UTF-16 and UTF-32.
|
||||
|
||||
## Template parameters
|
||||
@@ -34,7 +34,10 @@ static basic_json parse(IteratorType first, IteratorType last,
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type
|
||||
: a compatible iterator type, for instance.
|
||||
|
||||
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
|
||||
- a pair of pointers such as `ptr` and `ptr + len`
|
||||
|
||||
## Parameters
|
||||
|
||||
@@ -135,6 +138,34 @@ super-linear complexity.
|
||||
--8<-- "examples/parse__contiguouscontainer__parser_callback_t.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from a non null-terminated string"
|
||||
|
||||
The example below demonstrates the `parse()` function reading from a string that is not null-terminated.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/parse__pointers.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/parse__pointers.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from an iterator pair"
|
||||
|
||||
The example below demonstrates the `parse()` function reading from an iterator pair.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/parse__iterator_pair.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/parse__iterator_pair.output"
|
||||
```
|
||||
|
||||
??? example "Effect of `allow_exceptions` parameter"
|
||||
|
||||
The example below demonstrates the effect of the `allow_exceptions` parameter in the ´parse()` function.
|
||||
|
||||
Reference in New Issue
Block a user