mirror of
https://github.com/nlohmann/json.git
synced 2025-08-07 18:02:57 +03:00
deploy: 4b17f90f65
This commit is contained in:
31
examples/comments.cpp
Normal file
31
examples/comments.cpp
Normal file
@@ -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';
|
||||
}
|
Reference in New Issue
Block a user