mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
Merge branch 'master' of https://github.com/nlohmann/json
This commit is contained in:
@ -26,8 +26,8 @@ int main()
|
||||
{
|
||||
object.at("the fast") = "il rapido";
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
catch (std::out_of_range& e)
|
||||
{
|
||||
std::cout << "out of range" << '\n';
|
||||
std::cout << "out of range: " << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/syN4hQrhPvlUy5AG"><b>online</b></a>
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/3ir8W1OZ5KtbRz6r"><b>online</b></a>
|
@ -1,3 +1,3 @@
|
||||
"il brutto"
|
||||
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
|
||||
out of range
|
||||
out of range: key 'the fast' not found
|
||||
|
@ -21,8 +21,8 @@ int main()
|
||||
{
|
||||
array.at(5) = "sixth";
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
catch (std::out_of_range& e)
|
||||
{
|
||||
std::cout << "out of range" << '\n';
|
||||
std::cout << "out of range: " << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/wKBBW3ORmTHPlgJV"><b>online</b></a>
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/9Ae4DO4HJjULnq5j"><b>online</b></a>
|
@ -1,3 +1,3 @@
|
||||
"third"
|
||||
["first","second","third","fourth"]
|
||||
out of range
|
||||
out of range: array index 5 is out of range
|
||||
|
29
doc/examples/basic_json__value.cpp
Normal file
29
doc/examples/basic_json__value.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON object with different entry types
|
||||
json j =
|
||||
{
|
||||
{"integer", 1},
|
||||
{"floating", 42.23},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", {{"key1", 1}, {"key2", 2}}},
|
||||
{"array", {1, 2, 3}}
|
||||
};
|
||||
|
||||
// access existing values
|
||||
int v_integer = j.value("integer", 0);
|
||||
double v_floating = j.value("floating", 47.11);
|
||||
|
||||
// access nonexisting values and rely on default value
|
||||
std::string v_string = j.value("nonexisting", "oops");
|
||||
bool v_boolean = j.value("nonexisting", false);
|
||||
|
||||
// output values
|
||||
std::cout << std::boolalpha << v_integer << " " << v_floating
|
||||
<< " " << v_string << " " << v_boolean << "\n";
|
||||
}
|
1
doc/examples/basic_json__value.link
Normal file
1
doc/examples/basic_json__value.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/pehnjdIduvv90qfX"><b>online</b></a>
|
1
doc/examples/basic_json__value.output
Normal file
1
doc/examples/basic_json__value.output
Normal file
@ -0,0 +1 @@
|
||||
1 42.23 oops false
|
@ -5,7 +5,7 @@ using namespace nlohmann;
|
||||
int main()
|
||||
{
|
||||
// create a JSON object
|
||||
json object =
|
||||
const json object =
|
||||
{
|
||||
{"one", 1}, {"two", 2}, {"three", 2.9}
|
||||
};
|
||||
|
@ -1 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/9X5Q8p7DlWA6v0Ey"><b>online</b></a>
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/4WLxv7id8P64Q1KI"><b>online</b></a>
|
Reference in New Issue
Block a user