1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-29 23:01:16 +03:00

more documentation

This commit is contained in:
Niels
2015-06-21 09:44:12 +02:00
parent bb13c931b3
commit c40e85920f
20 changed files with 602 additions and 42 deletions

View File

@ -1,21 +1,9 @@
/*!
@mainpage
See @ref nlohmann::basic_json
@copyright Niels Lohmann\n
@include "../../LICENSE.MIT"
*/
/*!
@defgroup container Container
@brief methods and types to satisfy the Container requirements
A Container is an object used to store other objects and taking care of the
management of the memory used by the objects it contains.
@see http://en.cppreference.com/w/cpp/concept/Container
*/
/*!
@defgroup reversiblecontainer Reversible Container
*/

18
docs/examples/array.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON arrays
json j_no_init_list = json::array();
json j_empty_init_list = json::array({});
json j_nonempty_init_list = json::array({1, 2, 3, 4});
json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} });
// serialize the JSON arrays
std::cout << j_no_init_list << '\n';
std::cout << j_empty_init_list << '\n';
std::cout << j_nonempty_init_list << '\n';
std::cout << j_list_of_pairs << '\n';
}

View File

@ -0,0 +1,4 @@
[]
[]
[1,2,3,4]
[["one",1],["two",2]]

View File

@ -0,0 +1,20 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json j_empty_init_list = json({});
json j_object = { {"one", 1}, {"two", 2} };
json j_array = {1, 2, 3, 4};
json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
// serialize the JSON value
std::cout << j_empty_init_list << '\n';
std::cout << j_object << '\n';
std::cout << j_array << '\n';
std::cout << j_nested_object << '\n';
std::cout << j_nested_array << '\n';
}

View File

@ -0,0 +1,5 @@
{}
{"one":1,"two":2}
[1,2,3,4]
{"one":[1],"two":[1,2]}
[[[1],"one"],[[1,2],"two"]]

View File

@ -0,0 +1,17 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create an array by creating copies of a JSON value
json value = "Hello";
json array_0 = json(0, value);
json array_1 = json(1, value);
json array_5 = json(5, value);
// serialize the JSON arrays
std::cout << array_0 << '\n';
std::cout << array_1 << '\n';
std::cout << array_5 << '\n';
}

View File

@ -0,0 +1,3 @@
[]
["Hello"]
["Hello","Hello","Hello","Hello","Hello"]

33
docs/examples/clear.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";
// call clear()
j_null.clear();
j_boolean.clear();
j_number_integer.clear();
j_number_float.clear();
j_object.clear();
j_array.clear();
j_string.clear();
// serialize the cleared values()
std::cout << j_null << '\n';
std::cout << j_boolean << '\n';
std::cout << j_number_integer << '\n';
std::cout << j_number_float << '\n';
std::cout << j_object << '\n';
std::cout << j_array << '\n';
std::cout << j_string << '\n';
}

View File

@ -0,0 +1,7 @@
null
false
0
0
{}
[]
""

View File

@ -0,0 +1,24 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";
// call max_size()
std::cout << j_null.max_size() << '\n';
std::cout << j_boolean.max_size() << '\n';
std::cout << j_number_integer.max_size() << '\n';
std::cout << j_number_float.max_size() << '\n';
std::cout << j_object.max_size() << '\n';
std::cout << j_array.max_size() << '\n';
std::cout << j_string.max_size() << '\n';
}

View File

@ -0,0 +1,7 @@
0
1
1
1
256204778801521550
1152921504606846975
1

17
docs/examples/object.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON arrays
json j_no_init_list = json::object();
json j_empty_init_list = json::object({});
json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} });
//json j_invalid_list = json::object({ "one", 1 }); // would throw
// serialize the JSON arrays
std::cout << j_no_init_list << '\n';
std::cout << j_empty_init_list << '\n';
std::cout << j_list_of_pairs << '\n';
}

View File

@ -0,0 +1,3 @@
{}
{}
{"one":1,"two":2}

7
docs/mylayout.css Normal file
View File

@ -0,0 +1,7 @@
.memtemplate {
display: none;
}
.memTemplParams {
display: none;
}

15
docs/mylayout_docset.css Normal file
View File

@ -0,0 +1,15 @@
.memtemplate {
display: none;
}
.memTemplParams {
display: none;
}
.navtab {
display: none;
}
#top, .footer {
display: none;
}