added documentation for erase functions

This commit is contained in:
Niels 2015-06-28 15:49:40 +02:00
parent 862e7000f4
commit 7d9cfb1b32
10 changed files with 327 additions and 34 deletions

View file

@ -0,0 +1,30 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
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 erase
j_boolean.erase(j_boolean.begin());
j_number_integer.erase(j_number_integer.begin());
j_number_float.erase(j_number_float.begin());
j_object.erase(j_object.find("two"));
j_array.erase(j_array.begin() + 2);
j_string.erase(j_string.begin());
// print values
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,6 @@
null
null
null
{"one":1}
[1,2,8,16]
null

View file

@ -0,0 +1,30 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
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 erase
j_boolean.erase(j_boolean.begin(), j_boolean.end());
j_number_integer.erase(j_number_integer.begin(), j_number_integer.end());
j_number_float.erase(j_number_float.begin(), j_number_float.end());
j_object.erase(j_object.find("two"), j_object.end());
j_array.erase(j_array.begin() + 1, j_array.begin() + 3);
j_string.erase(j_string.begin(), j_string.end());
// print values
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,6 @@
null
null
null
{"one":1}
[1,8,16]
null

View file

@ -0,0 +1,17 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON object
json j_object = {{"one", 1}, {"two", 2}};
// call erase
auto count_one = j_object.erase("one");
auto count_three = j_object.erase("three");
// print values
std::cout << j_object << '\n';
std::cout << count_one << " " << count_three << '\n';
}

View file

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

View file

@ -0,0 +1,15 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON array
json j_array = {0, 1, 2, 3, 4, 5};
// call erase
j_array.erase(2);
// print values
std::cout << j_array << '\n';
}

View file

@ -0,0 +1 @@
[0,1,3,4,5]