2017-07-09 12:51:38 +03:00
|
|
|
#include <iostream>
|
2018-02-02 00:20:26 +03:00
|
|
|
#include <nlohmann/json.hpp>
|
2016-11-11 21:29:14 +03:00
|
|
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
|
|
|
|
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
|
2016-11-28 20:33:46 +03:00
|
|
|
auto res1 = object.emplace("three", 3);
|
2016-11-11 21:29:14 +03:00
|
|
|
null.emplace("A", "a");
|
|
|
|
null.emplace("B", "b");
|
|
|
|
|
2016-11-28 20:33:46 +03:00
|
|
|
// the following call will not add an object, because there is already
|
|
|
|
// a value stored at key "B"
|
|
|
|
auto res2 = null.emplace("B", "c");
|
|
|
|
|
2016-11-11 21:29:14 +03:00
|
|
|
// print values
|
|
|
|
std::cout << object << '\n';
|
2016-11-28 20:33:46 +03:00
|
|
|
std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n';
|
|
|
|
|
2016-11-11 21:29:14 +03:00
|
|
|
std::cout << null << '\n';
|
2016-11-28 20:33:46 +03:00
|
|
|
std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n';
|
2016-11-11 21:29:14 +03:00
|
|
|
}
|