2016-11-11 18:29:14 +00:00
|
|
|
#include <json.hpp>
|
|
|
|
|
|
|
|
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 17:33:46 +00:00
|
|
|
auto res1 = object.emplace("three", 3);
|
2016-11-11 18:29:14 +00:00
|
|
|
null.emplace("A", "a");
|
|
|
|
null.emplace("B", "b");
|
|
|
|
|
2016-11-28 17:33:46 +00: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 18:29:14 +00:00
|
|
|
// print values
|
|
|
|
std::cout << object << '\n';
|
2016-11-28 17:33:46 +00:00
|
|
|
std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n';
|
|
|
|
|
2016-11-11 18:29:14 +00:00
|
|
|
std::cout << null << '\n';
|
2016-11-28 17:33:46 +00:00
|
|
|
std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n';
|
2016-11-11 18:29:14 +00:00
|
|
|
}
|