Merge branch 'develop' into feature/rfc7396
This commit is contained in:
commit
0e8f01a963
134 changed files with 20390 additions and 1770 deletions
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/yCTCvQi0ZVxGuL3L"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/Op57X0V7fTf2tdwl"><b>online</b></a>
|
|
@ -79,6 +79,17 @@ int main()
|
|||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
// out_of_range.403
|
||||
try
|
||||
{
|
||||
// try to use a JSON pointer to an nonexistent object key
|
||||
json::const_reference ref = j.at("/foo"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
// out_of_range.404
|
||||
try
|
||||
{
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/mlj2WqOtwBidvuJx"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/3RO0naQeY3cWXNAz"><b>online</b></a>
|
|
@ -8,4 +8,5 @@
|
|||
[json.exception.parse_error.109] parse error: array index 'one' is not a number
|
||||
[json.exception.out_of_range.401] array index 4 is out of range
|
||||
[json.exception.out_of_range.402] array index '-' (2) is out of range
|
||||
[json.exception.out_of_range.403] key 'foo' not found
|
||||
[json.exception.out_of_range.404] unresolved reference token 'foo'
|
||||
|
|
|
@ -55,6 +55,17 @@ int main()
|
|||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
// out_of_range.403
|
||||
try
|
||||
{
|
||||
// try to use a JSON pointer to an nonexistent object key
|
||||
json::const_reference ref = j.at("/foo"_json_pointer);
|
||||
}
|
||||
catch (json::out_of_range& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
|
||||
// out_of_range.404
|
||||
try
|
||||
{
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/vHKlyYl9DwaUO9UN"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/LwtGNqrGgjcWey3P"><b>online</b></a>
|
|
@ -5,4 +5,5 @@
|
|||
[json.exception.parse_error.109] parse error: array index 'one' is not a number
|
||||
[json.exception.out_of_range.401] array index 4 is out of range
|
||||
[json.exception.out_of_range.402] array index '-' (2) is out of range
|
||||
[json.exception.out_of_range.403] key 'foo' not found
|
||||
[json.exception.out_of_range.404] unresolved reference token 'foo'
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/DKPu3VnNVgsQbaSX"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/QJlGaO7RqgvibCbR"><b>online</b></a>
|
|
@ -28,4 +28,15 @@ int main()
|
|||
std::cout << "strings:" << '\n'
|
||||
<< j_string.dump() << '\n'
|
||||
<< j_string.dump(-1, ' ', true) << '\n';
|
||||
|
||||
// create JSON value with invalid UTF-8 byte sequence
|
||||
json j_invalid = "\xF0\xA4\xAD\xC0";
|
||||
try
|
||||
{
|
||||
std::cout << j_invalid.dump() << std::endl;
|
||||
}
|
||||
catch (json::type_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/UnV6etCOZZRZpYyB"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/mHH9TibITCYPpLwy"><b>online</b></a>
|
|
@ -50,3 +50,4 @@ arrays:
|
|||
strings:
|
||||
"Hellö 😀!"
|
||||
"Hell\u00f6 \ud83d\ude00!"
|
||||
[json.exception.type_error.316] invalid UTF-8 byte at index 3: 0xC0
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/TpEB8tou7Wuyprkm"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/EBqdb2uhXyKTbr9f"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/X9wSCDZNg82T3oix"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/NkSIj6G89DXRXX9u"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/9MjZO7niLtZaJIIx"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/DlKRo80ESI428gH8"><b>online</b></a>
|
23
doc/examples/items.cpp
Normal file
23
doc/examples/items.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <iostream>
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create JSON values
|
||||
json j_object = {{"one", 1}, {"two", 2}};
|
||||
json j_array = {1, 2, 4, 8, 16};
|
||||
|
||||
// example for an object
|
||||
for (auto& x : j_object.items())
|
||||
{
|
||||
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
|
||||
}
|
||||
|
||||
// example for an array
|
||||
for (auto& x : j_array.items())
|
||||
{
|
||||
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
|
||||
}
|
||||
}
|
1
doc/examples/items.link
Normal file
1
doc/examples/items.link
Normal file
|
@ -0,0 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/E7h0HOuw778Ski8S"><b>online</b></a>
|
7
doc/examples/items.output
Normal file
7
doc/examples/items.output
Normal file
|
@ -0,0 +1,7 @@
|
|||
key: one, value: 1
|
||||
key: two, value: 2
|
||||
key: 0, value: 1
|
||||
key: 1, value: 2
|
||||
key: 2, value: 4
|
||||
key: 3, value: 8
|
||||
key: 4, value: 16
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/M9jbzex4Xj2l25ce"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/mtnyQGVjmAoHVvaP"><b>online</b></a>
|
|
@ -2,16 +2,16 @@
|
|||
"compiler": {
|
||||
"c++": "201103",
|
||||
"family": "clang",
|
||||
"version": "8.1.0 (clang-802.0.42)"
|
||||
"version": "9.0.0 (clang-900.0.39.2)"
|
||||
},
|
||||
"copyright": "(C) 2013-2017 Niels Lohmann",
|
||||
"name": "JSON for Modern C++",
|
||||
"platform": "apple",
|
||||
"url": "https://github.com/nlohmann/json",
|
||||
"version": {
|
||||
"major": 2,
|
||||
"minor": 1,
|
||||
"major": 3,
|
||||
"minor": 0,
|
||||
"patch": 1,
|
||||
"string": "2.1.1"
|
||||
"string": "3.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/atomVJKVgMTIh1iT"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/qrMPH8rv4FBqE2Ri"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/0Ec7N50CDWAWPWEE"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/9j30rS3lws0iiHPd"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/iG5QR4oqgCLaEedf"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/bYLh2weuTo9jkR5V"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/fs7n9Xh41pSIxK4g"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/12CMBHX694yrt0i9"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/2cJ6aEoQItmXOyEe"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/YDBQGKfyJUePDpRe"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/IvIGk03HXpuyv271"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/DhwTP8AtK5UoeF55"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/a8XRIpnVOQp3zYKV"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/c4K2s7QuFNfXd3j7"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/JZ8P4ruGJTLfOFHJ"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/GKABhikWJQTHeX7z"><b>online</b></a>
|
|
@ -1,6 +1,5 @@
|
|||
#include <iostream>
|
||||
#include "json.hpp"
|
||||
#include <iomanip> // for std::setw
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/U9n8nunch9ti8XlQ"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/QVr68rXTR2kztpbl"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/m6XKVQBrhB6jXGOe"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/ze9XofH6xAKtIha1"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/b66iY9hOdCHEG8FV"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/k8bMpRumLfsA8ylM"><b>online</b></a>
|
|
@ -1,5 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for std::setw
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<a target="_blank" href="https://wandbox.org/permlink/WKkNkEuGbsxPknyT"><b>online</b></a>
|
||||
<a target="_blank" href="https://wandbox.org/permlink/hvj393WgvjIaiUZe"><b>online</b></a>
|
Loading…
Add table
Add a link
Reference in a new issue