1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-29 23:01:16 +03:00
This commit is contained in:
dariomt
2016-01-18 10:08:58 +01:00
23 changed files with 6245 additions and 2746 deletions

View File

@ -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';
}
}

View File

@ -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>

View File

@ -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

View File

@ -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';
}
}

View File

@ -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>

View File

@ -1,3 +1,3 @@
"third"
["first","second","third","fourth"]
out of range
out of range: array index 5 is out of range

View 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";
}

View File

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/pehnjdIduvv90qfX"><b>online</b></a>

View File

@ -0,0 +1 @@
1 42.23 oops false

View File

@ -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}
};

View File

@ -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>