mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
overworked doxygen
This commit is contained in:
25
docs/examples/Makefile
Normal file
25
docs/examples/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
SRCDIR = ../../src
|
||||
|
||||
EXAMPLES = $(wildcard *.cpp)
|
||||
|
||||
all:
|
||||
@echo "check"
|
||||
@echo "create"
|
||||
|
||||
clean:
|
||||
rm -f $(EXAMPLES:.cpp=) $(EXAMPLES:.cpp=.output) $(EXAMPLES:.cpp=.test)
|
||||
|
||||
%.output: %.cpp
|
||||
make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11"
|
||||
./$(<:.cpp=) > $@
|
||||
rm $(<:.cpp=)
|
||||
|
||||
%.test: %.cpp
|
||||
make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11"
|
||||
./$(<:.cpp=) > $@
|
||||
diff $@ $(<:.cpp=.output)
|
||||
rm $(<:.cpp=) $@
|
||||
|
||||
create: $(EXAMPLES:.cpp=.output)
|
||||
|
||||
check: $(EXAMPLES:.cpp=.test)
|
12
docs/examples/basic_json.cpp
Normal file
12
docs/examples/basic_json.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON value with default null value
|
||||
json j;
|
||||
|
||||
// serialize the JSON null value
|
||||
std::cout << j << '\n';
|
||||
}
|
1
docs/examples/basic_json.output
Normal file
1
docs/examples/basic_json.output
Normal file
@ -0,0 +1 @@
|
||||
null
|
58
docs/examples/basic_json__CompatibleArrayType.cpp
Normal file
58
docs/examples/basic_json__CompatibleArrayType.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <json.hpp>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <forward_list>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array from std::vector
|
||||
std::vector<int> c_vector {1, 2, 3, 4};
|
||||
json j_vec(c_vector);
|
||||
|
||||
// create an array from std::deque
|
||||
std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
|
||||
json j_deque(c_deque);
|
||||
|
||||
// create an array from std::list
|
||||
std::list<bool> c_list {true, true, false, true};
|
||||
json j_list(c_list);
|
||||
|
||||
// create an array from std::forward_list
|
||||
std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
|
||||
json j_flist(c_flist);
|
||||
|
||||
// create an array from std::array
|
||||
std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
|
||||
json j_array(c_array);
|
||||
|
||||
// create an array from std::set
|
||||
std::set<std::string> c_set {"one", "two", "three", "four", "one"};
|
||||
json j_set(c_set); // only one entry for "one" is used
|
||||
|
||||
// create an array from std::unordered_set
|
||||
std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
|
||||
json j_uset(c_uset); // only one entry for "one" is used
|
||||
|
||||
// create an array from std::multiset
|
||||
std::multiset<std::string> c_mset {"one", "two", "one", "four"};
|
||||
json j_mset(c_mset); // only one entry for "one" is used
|
||||
|
||||
// create an array from std::unordered_multiset
|
||||
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
|
||||
json j_umset(c_umset); // both entries for "one" are used
|
||||
|
||||
// serialize the JSON arrays
|
||||
std::cout << j_vec << '\n';
|
||||
std::cout << j_deque << '\n';
|
||||
std::cout << j_list << '\n';
|
||||
std::cout << j_flist << '\n';
|
||||
std::cout << j_array << '\n';
|
||||
std::cout << j_set << '\n';
|
||||
std::cout << j_uset << '\n';
|
||||
std::cout << j_mset << '\n';
|
||||
std::cout << j_umset << '\n';
|
||||
}
|
9
docs/examples/basic_json__CompatibleArrayType.output
Normal file
9
docs/examples/basic_json__CompatibleArrayType.output
Normal file
@ -0,0 +1,9 @@
|
||||
[1,2,3,4]
|
||||
[1.2,2.3,3.4,5.6]
|
||||
[true,true,false,true]
|
||||
[12345678909876,23456789098765,34567890987654,45678909876543]
|
||||
[1,2,3,4]
|
||||
["four","one","three","two"]
|
||||
["four","three","two","one"]
|
||||
["four","one","one","two"]
|
||||
["four","two","one","one"]
|
41
docs/examples/basic_json__CompatibleObjectType.cpp
Normal file
41
docs/examples/basic_json__CompatibleObjectType.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <json.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an object from std::map
|
||||
std::map<std::string, int> c_map
|
||||
{
|
||||
{"one", 1}, {"two", 2}, {"three", 3}
|
||||
};
|
||||
json j_map(c_map);
|
||||
|
||||
// create an object from std::unordered_map
|
||||
std::unordered_map<const char*, double> c_umap
|
||||
{
|
||||
{"one", 1.2}, {"two", 2.3}, {"three", 3.4}
|
||||
};
|
||||
json j_umap(c_umap);
|
||||
|
||||
// create an object from std::multimap
|
||||
std::multimap<std::string, bool> c_mmap
|
||||
{
|
||||
{"one", true}, {"two", true}, {"three", false}, {"three", true}
|
||||
};
|
||||
json j_mmap(c_mmap); // only one entry for key "three" is used
|
||||
|
||||
// create an object from std::unordered_multimap
|
||||
std::unordered_multimap<std::string, bool> c_ummap
|
||||
{
|
||||
{"one", true}, {"two", true}, {"three", false}, {"three", true}
|
||||
};
|
||||
json j_ummap(c_ummap); // only one entry for key "three" is used
|
||||
|
||||
// serialize the JSON objects
|
||||
std::cout << j_map << '\n';
|
||||
std::cout << j_umap << '\n';
|
||||
std::cout << j_mmap << '\n';
|
||||
std::cout << j_ummap << '\n';
|
||||
}
|
4
docs/examples/basic_json__CompatibleObjectType.output
Normal file
4
docs/examples/basic_json__CompatibleObjectType.output
Normal file
@ -0,0 +1,4 @@
|
||||
{"one":1,"three":3,"two":2}
|
||||
{"one":1.2,"three":3.4,"two":2.3}
|
||||
{"one":true,"three":false,"two":true}
|
||||
{"one":true,"three":false,"two":true}
|
15
docs/examples/basic_json__array_t.cpp
Normal file
15
docs/examples/basic_json__array_t.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array_t value
|
||||
json::array_t value = {"one", "two", 3, 4.5, false};
|
||||
|
||||
// create a JSON array from the value
|
||||
json j(value);
|
||||
|
||||
// serialize the JSON array
|
||||
std::cout << j << '\n';
|
||||
}
|
1
docs/examples/basic_json__array_t.output
Normal file
1
docs/examples/basic_json__array_t.output
Normal file
@ -0,0 +1 @@
|
||||
["one","two",3,4.5,false]
|
16
docs/examples/basic_json__basic_json.cpp
Normal file
16
docs/examples/basic_json__basic_json.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON array
|
||||
json j1 = {"one", "two", 3, 4.5, false};
|
||||
|
||||
// create a copy
|
||||
json j2(j1);
|
||||
|
||||
// serialize the JSON array
|
||||
std::cout << j1 << " = " << j2 << '\n';
|
||||
std::cout << std::boolalpha << (j1 == j2) << '\n';
|
||||
}
|
2
docs/examples/basic_json__basic_json.output
Normal file
2
docs/examples/basic_json__basic_json.output
Normal file
@ -0,0 +1,2 @@
|
||||
["one","two",3,4.5,false] = ["one","two",3,4.5,false]
|
||||
true
|
12
docs/examples/basic_json__nullptr_t.cpp
Normal file
12
docs/examples/basic_json__nullptr_t.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON null value
|
||||
json j(nullptr);
|
||||
|
||||
// serialize the JSON null value
|
||||
std::cout << j << '\n';
|
||||
}
|
1
docs/examples/basic_json__nullptr_t.output
Normal file
1
docs/examples/basic_json__nullptr_t.output
Normal file
@ -0,0 +1 @@
|
||||
null
|
15
docs/examples/basic_json__object_t.cpp
Normal file
15
docs/examples/basic_json__object_t.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an object_t value
|
||||
json::object_t value = { {"one", 1}, {"two", 2} };
|
||||
|
||||
// create a JSON object from the value
|
||||
json j(value);
|
||||
|
||||
// serialize the JSON object
|
||||
std::cout << j << '\n';
|
||||
}
|
1
docs/examples/basic_json__object_t.output
Normal file
1
docs/examples/basic_json__object_t.output
Normal file
@ -0,0 +1 @@
|
||||
{"one":1,"two":2}
|
24
docs/examples/basic_json__value_t.cpp
Normal file
24
docs/examples/basic_json__value_t.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create the different JSON values with default values
|
||||
json j_null(json::value_t::null);
|
||||
json j_boolean(json::value_t::boolean);
|
||||
json j_number_integer(json::value_t::number_integer);
|
||||
json j_number_float(json::value_t::number_float);
|
||||
json j_object(json::value_t::object);
|
||||
json j_array(json::value_t::array);
|
||||
json j_string(json::value_t::string);
|
||||
|
||||
// serialize the JSON 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';
|
||||
}
|
7
docs/examples/basic_json__value_t.output
Normal file
7
docs/examples/basic_json__value_t.output
Normal file
@ -0,0 +1,7 @@
|
||||
null
|
||||
false
|
||||
0
|
||||
0
|
||||
{}
|
||||
[]
|
||||
""
|
15
docs/examples/begin.cpp
Normal file
15
docs/examples/begin.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get am iterator to the first element
|
||||
json::iterator it = array.begin();
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/begin.output
Normal file
1
docs/examples/begin.output
Normal file
@ -0,0 +1 @@
|
||||
1
|
15
docs/examples/cbegin.cpp
Normal file
15
docs/examples/cbegin.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
const json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get am iterator to the first element
|
||||
json::const_iterator it = array.cbegin();
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/cbegin.output
Normal file
1
docs/examples/cbegin.output
Normal file
@ -0,0 +1 @@
|
||||
1
|
18
docs/examples/cend.cpp
Normal file
18
docs/examples/cend.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get am iterator to one past the last element
|
||||
json::const_iterator it = array.cend();
|
||||
|
||||
// decrement the iterator to point to the last element
|
||||
--it;
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/cend.output
Normal file
1
docs/examples/cend.output
Normal file
@ -0,0 +1 @@
|
||||
5
|
15
docs/examples/crbegin.cpp
Normal file
15
docs/examples/crbegin.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get an iterator to the reverse-beginning
|
||||
json::const_reverse_iterator it = array.crbegin();
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/crbegin.output
Normal file
1
docs/examples/crbegin.output
Normal file
@ -0,0 +1 @@
|
||||
5
|
18
docs/examples/crend.cpp
Normal file
18
docs/examples/crend.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get an iterator to the reverse-end
|
||||
json::const_reverse_iterator it = array.crend();
|
||||
|
||||
// increment the iterator to point to the first element
|
||||
--it;
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/crend.output
Normal file
1
docs/examples/crend.output
Normal file
@ -0,0 +1 @@
|
||||
1
|
29
docs/examples/empty.cpp
Normal file
29
docs/examples/empty.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#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_object_empty(json::value_t::object);
|
||||
json j_array = {1, 2, 4, 8, 16};
|
||||
json j_array_empty(json::value_t::array);
|
||||
json j_string = "Hello, world";
|
||||
|
||||
// call empty()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.empty() << '\n';
|
||||
std::cout << j_boolean.empty() << '\n';
|
||||
std::cout << j_number_integer.empty() << '\n';
|
||||
std::cout << j_number_float.empty() << '\n';
|
||||
std::cout << j_object.empty() << '\n';
|
||||
std::cout << j_object_empty.empty() << '\n';
|
||||
std::cout << j_array.empty() << '\n';
|
||||
std::cout << j_array_empty.empty() << '\n';
|
||||
std::cout << j_string.empty() << '\n';
|
||||
}
|
9
docs/examples/empty.output
Normal file
9
docs/examples/empty.output
Normal file
@ -0,0 +1,9 @@
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
18
docs/examples/end.cpp
Normal file
18
docs/examples/end.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get am iterator to one past the last element
|
||||
json::iterator it = array.end();
|
||||
|
||||
// decrement the iterator to point to the last element
|
||||
--it;
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/end.output
Normal file
1
docs/examples/end.output
Normal file
@ -0,0 +1 @@
|
||||
5
|
25
docs/examples/is_array.cpp
Normal file
25
docs/examples/is_array.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_array()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_array() << '\n';
|
||||
std::cout << j_boolean.is_array() << '\n';
|
||||
std::cout << j_number_integer.is_array() << '\n';
|
||||
std::cout << j_number_float.is_array() << '\n';
|
||||
std::cout << j_object.is_array() << '\n';
|
||||
std::cout << j_array.is_array() << '\n';
|
||||
std::cout << j_string.is_array() << '\n';
|
||||
}
|
7
docs/examples/is_array.output
Normal file
7
docs/examples/is_array.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
false
|
25
docs/examples/is_boolean.cpp
Normal file
25
docs/examples/is_boolean.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_boolean()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_boolean() << '\n';
|
||||
std::cout << j_boolean.is_boolean() << '\n';
|
||||
std::cout << j_number_integer.is_boolean() << '\n';
|
||||
std::cout << j_number_float.is_boolean() << '\n';
|
||||
std::cout << j_object.is_boolean() << '\n';
|
||||
std::cout << j_array.is_boolean() << '\n';
|
||||
std::cout << j_string.is_boolean() << '\n';
|
||||
}
|
7
docs/examples/is_boolean.output
Normal file
7
docs/examples/is_boolean.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
25
docs/examples/is_null.cpp
Normal file
25
docs/examples/is_null.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_null()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_null() << '\n';
|
||||
std::cout << j_boolean.is_null() << '\n';
|
||||
std::cout << j_number_integer.is_null() << '\n';
|
||||
std::cout << j_number_float.is_null() << '\n';
|
||||
std::cout << j_object.is_null() << '\n';
|
||||
std::cout << j_array.is_null() << '\n';
|
||||
std::cout << j_string.is_null() << '\n';
|
||||
}
|
7
docs/examples/is_null.output
Normal file
7
docs/examples/is_null.output
Normal file
@ -0,0 +1,7 @@
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
25
docs/examples/is_number.cpp
Normal file
25
docs/examples/is_number.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_number()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_number() << '\n';
|
||||
std::cout << j_boolean.is_number() << '\n';
|
||||
std::cout << j_number_integer.is_number() << '\n';
|
||||
std::cout << j_number_float.is_number() << '\n';
|
||||
std::cout << j_object.is_number() << '\n';
|
||||
std::cout << j_array.is_number() << '\n';
|
||||
std::cout << j_string.is_number() << '\n';
|
||||
}
|
7
docs/examples/is_number.output
Normal file
7
docs/examples/is_number.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
false
|
||||
true
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
25
docs/examples/is_number_float.cpp
Normal file
25
docs/examples/is_number_float.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_number_float()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_number_float() << '\n';
|
||||
std::cout << j_boolean.is_number_float() << '\n';
|
||||
std::cout << j_number_integer.is_number_float() << '\n';
|
||||
std::cout << j_number_float.is_number_float() << '\n';
|
||||
std::cout << j_object.is_number_float() << '\n';
|
||||
std::cout << j_array.is_number_float() << '\n';
|
||||
std::cout << j_string.is_number_float() << '\n';
|
||||
}
|
7
docs/examples/is_number_float.output
Normal file
7
docs/examples/is_number_float.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
25
docs/examples/is_number_integer.cpp
Normal file
25
docs/examples/is_number_integer.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_number_integer()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_number_integer() << '\n';
|
||||
std::cout << j_boolean.is_number_integer() << '\n';
|
||||
std::cout << j_number_integer.is_number_integer() << '\n';
|
||||
std::cout << j_number_float.is_number_integer() << '\n';
|
||||
std::cout << j_object.is_number_integer() << '\n';
|
||||
std::cout << j_array.is_number_integer() << '\n';
|
||||
std::cout << j_string.is_number_integer() << '\n';
|
||||
}
|
7
docs/examples/is_number_integer.output
Normal file
7
docs/examples/is_number_integer.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
false
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
25
docs/examples/is_object.cpp
Normal file
25
docs/examples/is_object.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_object()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_object() << '\n';
|
||||
std::cout << j_boolean.is_object() << '\n';
|
||||
std::cout << j_number_integer.is_object() << '\n';
|
||||
std::cout << j_number_float.is_object() << '\n';
|
||||
std::cout << j_object.is_object() << '\n';
|
||||
std::cout << j_array.is_object() << '\n';
|
||||
std::cout << j_string.is_object() << '\n';
|
||||
}
|
7
docs/examples/is_object.output
Normal file
7
docs/examples/is_object.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
false
|
||||
false
|
25
docs/examples/is_string.cpp
Normal file
25
docs/examples/is_string.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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 is_string()
|
||||
std::cout << std::boolalpha;
|
||||
std::cout << j_null.is_string() << '\n';
|
||||
std::cout << j_boolean.is_string() << '\n';
|
||||
std::cout << j_number_integer.is_string() << '\n';
|
||||
std::cout << j_number_float.is_string() << '\n';
|
||||
std::cout << j_object.is_string() << '\n';
|
||||
std::cout << j_array.is_string() << '\n';
|
||||
std::cout << j_string.is_string() << '\n';
|
||||
}
|
7
docs/examples/is_string.output
Normal file
7
docs/examples/is_string.output
Normal file
@ -0,0 +1,7 @@
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
15
docs/examples/rbegin.cpp
Normal file
15
docs/examples/rbegin.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get an iterator to the reverse-beginning
|
||||
json::reverse_iterator it = array.rbegin();
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/rbegin.output
Normal file
1
docs/examples/rbegin.output
Normal file
@ -0,0 +1 @@
|
||||
5
|
18
docs/examples/rend.cpp
Normal file
18
docs/examples/rend.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create an array value
|
||||
json array = {1, 2, 3, 4, 5};
|
||||
|
||||
// get an iterator to the reverse-end
|
||||
json::reverse_iterator it = array.rend();
|
||||
|
||||
// increment the iterator to point to the first element
|
||||
--it;
|
||||
|
||||
// serialize the element that the iterator points to
|
||||
std::cout << *it << '\n';
|
||||
}
|
1
docs/examples/rend.output
Normal file
1
docs/examples/rend.output
Normal file
@ -0,0 +1 @@
|
||||
1
|
28
docs/examples/size.cpp
Normal file
28
docs/examples/size.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#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_object_empty(json::value_t::object);
|
||||
json j_array = {1, 2, 4, 8, 16};
|
||||
json j_array_empty(json::value_t::array);
|
||||
json j_string = "Hello, world";
|
||||
|
||||
// call size()
|
||||
std::cout << j_null.size() << '\n';
|
||||
std::cout << j_boolean.size() << '\n';
|
||||
std::cout << j_number_integer.size() << '\n';
|
||||
std::cout << j_number_float.size() << '\n';
|
||||
std::cout << j_object.size() << '\n';
|
||||
std::cout << j_object_empty.size() << '\n';
|
||||
std::cout << j_array.size() << '\n';
|
||||
std::cout << j_array_empty.size() << '\n';
|
||||
std::cout << j_string.size() << '\n';
|
||||
}
|
9
docs/examples/size.output
Normal file
9
docs/examples/size.output
Normal file
@ -0,0 +1,9 @@
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
2
|
||||
0
|
||||
5
|
||||
0
|
||||
1
|
Reference in New Issue
Block a user