mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
minor changes
This commit is contained in:
30
doc/examples/operatorarray__key_type.cpp
Normal file
30
doc/examples/operatorarray__key_type.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON object
|
||||
json object =
|
||||
{
|
||||
{"one", 1}, {"two", 2}, {"three", 2.9}
|
||||
};
|
||||
|
||||
// output element with key "two"
|
||||
std::cout << object["two"] << "\n\n";
|
||||
|
||||
// change element with key "three"
|
||||
object["three"] = 3;
|
||||
|
||||
// output changed array
|
||||
std::cout << std::setw(4) << object << "\n\n";
|
||||
|
||||
// mention nonexisting key
|
||||
object["four"];
|
||||
|
||||
// write to nonexisting key
|
||||
object["five"]["really"]["nested"] = true;
|
||||
|
||||
// output changed object
|
||||
std::cout << std::setw(4) << object << '\n';
|
||||
}
|
19
doc/examples/operatorarray__key_type.output
Normal file
19
doc/examples/operatorarray__key_type.output
Normal file
@ -0,0 +1,19 @@
|
||||
2
|
||||
|
||||
{
|
||||
"one": 1,
|
||||
"three": 3,
|
||||
"two": 2
|
||||
}
|
||||
|
||||
{
|
||||
"five": {
|
||||
"really": {
|
||||
"nested": true
|
||||
}
|
||||
},
|
||||
"four": null,
|
||||
"one": 1,
|
||||
"three": 3,
|
||||
"two": 2
|
||||
}
|
15
doc/examples/operatorarray__key_type_const.cpp
Normal file
15
doc/examples/operatorarray__key_type_const.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON object
|
||||
json object =
|
||||
{
|
||||
{"one", 1}, {"two", 2}, {"three", 2.9}
|
||||
};
|
||||
|
||||
// output element with key "two"
|
||||
std::cout << object["two"] << '\n';
|
||||
}
|
1
doc/examples/operatorarray__key_type_const.output
Normal file
1
doc/examples/operatorarray__key_type_const.output
Normal file
@ -0,0 +1 @@
|
||||
2
|
Reference in New Issue
Block a user