more documentation
This commit is contained in:
parent
f1c9aa26c4
commit
48545f5b18
14 changed files with 486 additions and 78 deletions
21
doc/examples/basic_json__CompatibleNumberFloatType.cpp
Normal file
21
doc/examples/basic_json__CompatibleNumberFloatType.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create values of different floating-point types
|
||||
float f42 = 42.23;
|
||||
float f_nan = 1.0f / 0.0f;
|
||||
double f23 = 23.42;
|
||||
|
||||
// create JSON numbers
|
||||
json j42(f42);
|
||||
json j_nan(f_nan);
|
||||
json j23(f23);
|
||||
|
||||
// serialize the JSON numbers
|
||||
std::cout << j42 << '\n';
|
||||
std::cout << j_nan << '\n';
|
||||
std::cout << j23 << '\n';
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
42.2299995422363
|
||||
null
|
||||
23.42
|
15
doc/examples/basic_json__CompatibleStringType.cpp
Normal file
15
doc/examples/basic_json__CompatibleStringType.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a string value
|
||||
std::string s = "The quick brown fox jumps over the lazy dog.";
|
||||
|
||||
// create a JSON string value
|
||||
json j = s;
|
||||
|
||||
// serialize the JSON string
|
||||
std::cout << j << '\n';
|
||||
}
|
1
doc/examples/basic_json__CompatibleStringType.output
Normal file
1
doc/examples/basic_json__CompatibleStringType.output
Normal file
|
@ -0,0 +1 @@
|
|||
"The quick brown fox jumps over the lazy dog."
|
21
doc/examples/basic_json__InputIt_InputIt.cpp
Normal file
21
doc/examples/basic_json__InputIt_InputIt.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create JSON values
|
||||
json j_array = {"alpha", "bravo", "charly", "delta", "easy"};
|
||||
json j_number = 42;
|
||||
json j_object = {{"one", "eins"}, {"two", "zwei"}};
|
||||
|
||||
// create copies using iterators
|
||||
json j_array_range(j_array.begin() + 1, j_array.end() - 2);
|
||||
json j_number_range(j_number.begin(), j_number.end());
|
||||
json j_object_range(j_object.begin(), j_object.find("two"));
|
||||
|
||||
// serialize the values
|
||||
std::cout << j_array_range << '\n';
|
||||
std::cout << j_number_range << '\n';
|
||||
std::cout << j_object_range << '\n';
|
||||
}
|
3
doc/examples/basic_json__InputIt_InputIt.output
Normal file
3
doc/examples/basic_json__InputIt_InputIt.output
Normal file
|
@ -0,0 +1,3 @@
|
|||
["bravo","charly"]
|
||||
42
|
||||
{"one":"eins"}
|
14
doc/examples/basic_json__boolean_t.cpp
Normal file
14
doc/examples/basic_json__boolean_t.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create boolean values
|
||||
json j_truth = true;
|
||||
json j_falsity = false;
|
||||
|
||||
// serialize the JSON booleans
|
||||
std::cout << j_truth << '\n';
|
||||
std::cout << j_falsity << '\n';
|
||||
}
|
2
doc/examples/basic_json__boolean_t.output
Normal file
2
doc/examples/basic_json__boolean_t.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
true
|
||||
false
|
15
doc/examples/basic_json__const_int.cpp
Normal file
15
doc/examples/basic_json__const_int.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// an anonymous enum
|
||||
enum { t = 17 };
|
||||
|
||||
// create a JSON number from the enum
|
||||
json j(t);
|
||||
|
||||
// serialize the JSON numbers
|
||||
std::cout << j << '\n';
|
||||
}
|
1
doc/examples/basic_json__const_int.output
Normal file
1
doc/examples/basic_json__const_int.output
Normal file
|
@ -0,0 +1 @@
|
|||
17
|
23
doc/examples/operator_deserialize.cpp
Normal file
23
doc/examples/operator_deserialize.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create stream with serialized JSON
|
||||
std::stringstream ss;
|
||||
ss << R"({
|
||||
"number": 23,
|
||||
"string": "Hello, world!",
|
||||
"array": [1, 2, 3, 4, 5],
|
||||
"boolean": false,
|
||||
"null": null
|
||||
})";
|
||||
|
||||
// create JSON value and read the serialization from the stream
|
||||
json j;
|
||||
j << ss;
|
||||
|
||||
// serialize JSON
|
||||
std::cout << std::setw(2) << j << '\n';
|
||||
}
|
13
doc/examples/operator_deserialize.output
Normal file
13
doc/examples/operator_deserialize.output
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"array": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
],
|
||||
"boolean": false,
|
||||
"null": null,
|
||||
"number": 23,
|
||||
"string": "Hello, world!"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue