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