Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
c4a4e672
Unverified
Commit
c4a4e672
authored
Oct 29, 2021
by
Niels Lohmann
Committed by
GitHub
Oct 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
📝
add examples for parsing from iterator pair (#3100)
parent
f5b3fb32
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
2 deletions
+77
-2
doc/examples/parse__iterator_pair.cpp
doc/examples/parse__iterator_pair.cpp
+15
-0
doc/examples/parse__iterator_pair.link
doc/examples/parse__iterator_pair.link
+1
-0
doc/examples/parse__iterator_pair.output
doc/examples/parse__iterator_pair.output
+6
-0
doc/examples/parse__pointers.cpp
doc/examples/parse__pointers.cpp
+15
-0
doc/examples/parse__pointers.link
doc/examples/parse__pointers.link
+1
-0
doc/examples/parse__pointers.output
doc/examples/parse__pointers.output
+6
-0
doc/mkdocs/docs/api/basic_json/parse.md
doc/mkdocs/docs/api/basic_json/parse.md
+33
-2
No files found.
doc/examples/parse__iterator_pair.cpp
0 → 100644
View file @
c4a4e672
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using
json
=
nlohmann
::
json
;
int
main
()
{
// a JSON text given an input with other values
std
::
vector
<
std
::
uint8_t
>
input
=
{
'['
,
'1'
,
','
,
'2'
,
','
,
'3'
,
']'
,
'o'
,
't'
,
'h'
,
'e'
,
'r'
};
// parse and serialize JSON
json
j_complete
=
json
::
parse
(
input
.
begin
(),
input
.
begin
()
+
7
);
std
::
cout
<<
std
::
setw
(
4
)
<<
j_complete
<<
"
\n\n
"
;
}
doc/examples/parse__iterator_pair.link
0 → 100644
View file @
c4a4e672
<a target="_blank" href="https://wandbox.org/permlink/hUJYo1HWmfTBLMGn"><b>online</b></a>
\ No newline at end of file
doc/examples/parse__iterator_pair.output
0 → 100644
View file @
c4a4e672
[
1,
2,
3
]
doc/examples/parse__pointers.cpp
0 → 100644
View file @
c4a4e672
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using
json
=
nlohmann
::
json
;
int
main
()
{
// a JSON text given as string that is not null-terminated
const
char
*
ptr
=
"[1,2,3]another value"
;
// parse and serialize JSON
json
j_complete
=
json
::
parse
(
ptr
,
ptr
+
7
);
std
::
cout
<<
std
::
setw
(
4
)
<<
j_complete
<<
"
\n\n
"
;
}
doc/examples/parse__pointers.link
0 → 100644
View file @
c4a4e672
<a target="_blank" href="https://wandbox.org/permlink/AWbpa8e1xRV3y4MM"><b>online</b></a>
\ No newline at end of file
doc/examples/parse__pointers.output
0 → 100644
View file @
c4a4e672
[
1,
2,
3
]
doc/mkdocs/docs/api/basic_json/parse.md
View file @
c4a4e672
...
@@ -19,7 +19,7 @@ static basic_json parse(IteratorType first, IteratorType last,
...
@@ -19,7 +19,7 @@ static basic_json parse(IteratorType first, IteratorType last,
1.
Deserialize from a compatible input.
1.
Deserialize from a compatible input.
2.
Deserialize from a pair of character iterators
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.
respectively as UTF-8, UTF-16 and UTF-32.
## Template parameters
## Template parameters
...
@@ -34,7 +34,10 @@ static basic_json parse(IteratorType first, IteratorType last,
...
@@ -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.
-
an object
`obj`
for which
`begin(obj)`
and
`end(obj)`
produces a valid pair of iterators.
`IteratorType`
`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
## Parameters
...
@@ -135,6 +138,34 @@ super-linear complexity.
...
@@ -135,6 +138,34 @@ super-linear complexity.
--8<-- "examples/parse__contiguouscontainer__parser_callback_t.output"
--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"
??? example "Effect of
`allow_exceptions`
parameter"
The example below demonstrates the effect of the `allow_exceptions` parameter in the ´parse()` function.
The example below demonstrates the effect of the `allow_exceptions` parameter in the ´parse()` function.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment