-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: chirsz-ever <chirsz@foxmail.com>
- Loading branch information
1 parent
b40faaf
commit e83580b
Showing
6 changed files
with
97 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#include <iostream> | ||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
std::string s = R"( | ||
{ | ||
// update in 2006: removed Pluto | ||
"planets": ["Mercury", "Venus", "Earth", "Mars", | ||
"Jupiter", "Uranus", "Neptune" /*, "Pluto" */] | ||
} | ||
)"; | ||
|
||
try | ||
{ | ||
json j = json::parse(s); | ||
} | ||
catch (json::exception &e) | ||
{ | ||
std::cout << e.what() << std::endl; | ||
} | ||
|
||
json j = json::parse(s, | ||
/* callback */ nullptr, | ||
/* allow exceptions */ true, | ||
/* ignore_comments */ true); | ||
std::cout << j.dump(2) << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[json.exception.parse_error.101] parse error at line 3, column 9: syntax error while parsing object key - invalid literal; last read: '<U+000A> {<U+000A> /'; expected string literal | ||
{ | ||
"planets": [ | ||
"Mercury", | ||
"Venus", | ||
"Earth", | ||
"Mars", | ||
"Jupiter", | ||
"Uranus", | ||
"Neptune" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <iostream> | ||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
std::string s = R"( | ||
{ | ||
"planets": [ | ||
"Mercury", | ||
"Venus", | ||
"Earth", | ||
"Mars", | ||
"Jupiter", | ||
"Uranus", | ||
"Neptune", | ||
] | ||
} | ||
)"; | ||
|
||
try | ||
{ | ||
json j = json::parse(s); | ||
} | ||
catch (json::exception &e) | ||
{ | ||
std::cout << e.what() << std::endl; | ||
} | ||
|
||
json j = json::parse(s, | ||
/* callback */ nullptr, | ||
/* allow exceptions */ true, | ||
/* ignore_comments */ false, | ||
/* ignore_trailing_commas */ true); | ||
std::cout << j.dump(2) << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[json.exception.parse_error.101] parse error at line 11, column 9: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal | ||
{ | ||
"planets": [ | ||
"Mercury", | ||
"Venus", | ||
"Earth", | ||
"Mars", | ||
"Jupiter", | ||
"Uranus", | ||
"Neptune" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters