Commit c012b29a authored by Niels's avatar Niels

worked on #102: more documentation and examples

parent 19d550c0
SRCDIR = ../src
all: doxygen
clean:
rm -fr me.nlohmann.json.docset html
......
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.000000000000001L;
json string_1 = "foo";
json string_2 = "bar";
// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 == array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 == object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 == number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 == string_2) << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/a74tSggkWP5Zo0Ee"><b>online</b></a>
\ No newline at end of file
[1,2,3] == [1,2,4] false
{"A":"a","B":"b"} == {"A":"a","B":"b"} true
17 == 17 true
"foo" == "bar" false
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";
// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 > array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 > object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 > number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 > string_2) << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/TZmhplJw3tl08RFN"><b>online</b></a>
\ No newline at end of file
[1,2,3] == [1,2,4] false
{"A":"a","B":"b"} == {"A":"a","B":"b"} false
17 == 17.0000000000001 false
"foo" == "bar" true
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";
// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " >= " << array_2 << " " << (array_1 >= array_2) << '\n';
std::cout << object_1 << " >= " << object_2 << " " << (object_1 >= object_2) << '\n';
std::cout << number_1 << " >= " << number_2 << " " << (number_1 >= number_2) << '\n';
std::cout << string_1 << " >= " << string_2 << " " << (string_1 >= string_2) << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/clvCFZxlFEerhtk8"><b>online</b></a>
\ No newline at end of file
[1,2,3] >= [1,2,4] false
{"A":"a","B":"b"} >= {"A":"a","B":"b"} true
17 >= 17.0000000000001 false
"foo" >= "bar" true
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";
// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 < array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 < object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 < number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 < string_2) << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/85XpxnwbJZR1PVtz"><b>online</b></a>
\ No newline at end of file
[1,2,3] == [1,2,4] true
{"A":"a","B":"b"} == {"A":"a","B":"b"} false
17 == 17.0000000000001 true
"foo" == "bar" false
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";
// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " <= " << array_2 << " " << (array_1 <= array_2) << '\n';
std::cout << object_1 << " <= " << object_2 << " " << (object_1 <= object_2) << '\n';
std::cout << number_1 << " <= " << number_2 << " " << (number_1 <= number_2) << '\n';
std::cout << string_1 << " <= " << string_2 << " " << (string_1 <= string_2) << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/JYP6JpBzl8Q9xQDZ"><b>online</b></a>
\ No newline at end of file
[1,2,3] <= [1,2,4] true
{"A":"a","B":"b"} <= {"A":"a","B":"b"} true
17 <= 17.0000000000001 true
"foo" <= "bar" false
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.000000000000001L;
json string_1 = "foo";
json string_2 = "bar";
// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 != array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 != object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 != number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 != string_2) << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/csiUCov9Mquff3ZZ"><b>online</b></a>
\ No newline at end of file
[1,2,3] == [1,2,4] true
{"A":"a","B":"b"} == {"A":"a","B":"b"} false
17 == 17 false
"foo" == "bar" true
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json array = {1, 2, 3, 4, 5};
json null;
// print values
std::cout << array << '\n';
std::cout << null << '\n';
// add values
array.push_back(6);
array += 7;
null += "first";
null += "second";
// print values
std::cout << array << '\n';
std::cout << null << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/5ZglUDvkQ0VxYxQ4"><b>online</b></a>
\ No newline at end of file
[1,2,3,4,5]
null
[1,2,3,4,5,6,7]
["first","second"]
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create JSON values
json object = {{"one", 1}, {"two", 2}};
json null;
// print values
std::cout << object << '\n';
std::cout << null << '\n';
// add values
object.push_back(json::object_t::value_type("three", 3));
object += json::object_t::value_type("four", 4);
null += json::object_t::value_type("A", "a");
null += json::object_t::value_type("B", "b");
// print values
std::cout << object << '\n';
std::cout << null << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/xtErbxTG2iIC5wHh"><b>online</b></a>
\ No newline at end of file
{"one":1,"two":2}
null
{"four":4,"one":1,"three":3,"two":2}
{"A":"a","B":"b"}
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON value
json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };
// create an object_t
json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};
// swap the object stored in the JSON value
value["translation"].swap(object);
// output the values
std::cout << "value = " << value << '\n';
std::cout << "object = " << object << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/g5pkLUCrBVoNPRyE"><b>online</b></a>
\ No newline at end of file
value = {"translation":{"cow":"Kuh","dog":"Hund"}}
object = {"one":"eins","two":"zwei"}
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON value
json value = { "the good", "the bad", "the ugly" };
// create string_t
json::string_t string = "the fast";
// swap the object stored in the JSON value
value[1].swap(string);
// output the values
std::cout << "value = " << value << '\n';
std::cout << "string = " << string << '\n';
}
<a target="_blank" href="http://melpon.org/wandbox/permlink/UsEo3yK2GsjH8CyA"><b>online</b></a>
\ No newline at end of file
value = ["the good","the fast","the ugly"]
string = the bad
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment