1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

more documentation

This commit is contained in:
Niels
2015-06-21 18:30:08 +02:00
parent d972483b33
commit 4bb5126502
9 changed files with 186 additions and 32 deletions

View File

@ -0,0 +1,17 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json a = 23;
json b = 42;
// copy-assign a to b
b = a;
// serialize the JSON arrays
std::cout << a << '\n';
std::cout << b << '\n';
}

View File

@ -0,0 +1,2 @@
23
23

View File

@ -0,0 +1,16 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON value
json a = 23;
// move contents of a to b
json b(std::move(a));
// serialize the JSON arrays
std::cout << a << '\n';
std::cout << b << '\n';
}

View File

@ -0,0 +1,2 @@
null
23

20
docs/examples/dump.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
// call dump()
std::cout << j_object.dump() << "\n\n";
std::cout << j_object.dump(-1) << "\n\n";
std::cout << j_object.dump(0) << "\n\n";
std::cout << j_object.dump(4) << "\n\n";
std::cout << j_array.dump() << "\n\n";
std::cout << j_array.dump(-1) << "\n\n";
std::cout << j_array.dump(0) << "\n\n";
std::cout << j_array.dump(4) << "\n\n";
}

34
docs/examples/dump.output Normal file
View File

@ -0,0 +1,34 @@
{"one":1,"two":2}
{"one":1,"two":2}
{
"one": 1,
"two": 2
}
{
"one": 1,
"two": 2
}
[1,2,4,8,16]
[1,2,4,8,16]
[
1,
2,
4,
8,
16
]
[
1,
2,
4,
8,
16
]