mirror of
https://github.com/nlohmann/json.git
synced 2026-10-09 16:07:14 +00:00
contains(json_pointer) is marked JSON_HEDLEY_WARN_UNUSED_RESULT since #5477, and parse() has been for longer. The contains example ignored the result in two try blocks waiting for a parse_error that contains() never throws, so they printed nothing; print the result for those pointers instead. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
21 lines
472 B
C++
21 lines
472 B
C++
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
int main()
|
|
{
|
|
try
|
|
{
|
|
// parsing input with a syntax error
|
|
json j = json::parse("[1,2,3,]");
|
|
}
|
|
catch (const json::parse_error& e)
|
|
{
|
|
// output exception information
|
|
std::cout << "message: " << e.what() << '\n'
|
|
<< "exception id: " << e.id << '\n'
|
|
<< "byte position of error: " << e.byte << std::endl;
|
|
}
|
|
}
|