mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
32 lines
668 B
C++
32 lines
668 B
C++
|
|
#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';
|
|
}
|