mirror of
https://github.com/nlohmann/json.git
synced 2025-06-08 04:17:31 +08:00

Added examples and modified the corresponding documents and unit tests. Signed-off-by: chirsz-ever <chirsz-ever@outlook.com> Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
38 lines
747 B
C++
38 lines
747 B
C++
#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';
|
|
}
|