xref: /third_party/json/docs/examples/parse_error.cpp (revision c5f01b2f)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ciusing json = nlohmann::json;
5c5f01b2fSopenharmony_ci
6c5f01b2fSopenharmony_ciint main()
7c5f01b2fSopenharmony_ci{
8c5f01b2fSopenharmony_ci    try
9c5f01b2fSopenharmony_ci    {
10c5f01b2fSopenharmony_ci        // parsing input with a syntax error
11c5f01b2fSopenharmony_ci        json::parse("[1,2,3,]");
12c5f01b2fSopenharmony_ci    }
13c5f01b2fSopenharmony_ci    catch (json::parse_error& e)
14c5f01b2fSopenharmony_ci    {
15c5f01b2fSopenharmony_ci        // output exception information
16c5f01b2fSopenharmony_ci        std::cout << "message: " << e.what() << '\n'
17c5f01b2fSopenharmony_ci                  << "exception id: " << e.id << '\n'
18c5f01b2fSopenharmony_ci                  << "byte position of error: " << e.byte << std::endl;
19c5f01b2fSopenharmony_ci    }
20c5f01b2fSopenharmony_ci}
21

Indexes created Thu Nov 07 10:32:03 CST 2024