1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-29 23:01:16 +03:00
This commit is contained in:
nlohmann
2025-01-19 09:46:40 +00:00
parent 6c9075c692
commit 32cf7af82a
242 changed files with 630 additions and 471 deletions

View File

@ -0,0 +1,30 @@
#include <iostream>
#define JSON_DIAGNOSTIC_POSITIONS 1
#include <nlohmann/json.hpp>
using json = nlohmann::json;
/* Demonstration of type error exception with diagnostic postions support enabled */
int main()
{
//Invalid json string - housenumber type must be int instead of string
const std::string json_invalid_string = R"(
{
"address": {
"street": "Fake Street",
"housenumber": "1"
}
}
)";
json j = json::parse(json_invalid_string);
try
{
int housenumber = j["address"]["housenumber"];
std::cout << housenumber;
}
catch (const json::exception& e)
{
std::cout << e.what() << '\n';
}
}

View File

@ -0,0 +1 @@
[json.exception.type_error.302] (bytes 92-95) type must be number, but is string

View File

@ -0,0 +1,31 @@
#include <iostream>
#define JSON_DIAGNOSTICS 1
#define JSON_DIAGNOSTIC_POSITIONS 1
#include <nlohmann/json.hpp>
using json = nlohmann::json;
/* Demonstration of type error exception with diagnostic postions support enabled */
int main()
{
//Invalid json string - housenumber type must be int instead of string
const std::string json_invalid_string = R"(
{
"address": {
"street": "Fake Street",
"housenumber": "1"
}
}
)";
json j = json::parse(json_invalid_string);
try
{
int housenumber = j["address"]["housenumber"];
std::cout << housenumber;
}
catch (const json::exception& e)
{
std::cout << e.what() << '\n';
}
}

View File

@ -0,0 +1 @@
[json.exception.type_error.302] (/address/housenumber) (bytes 92-95) type must be number, but is string