#include#include using json = nlohmann::json; int main() { // create JSON values json object = {{"one", 1}, {"two", 2}}; json null; // print values std::cout << object << 'n'; // expect {"one":1,"two":2} std::cout << null << 'n'; // expect null // emplace member function add values, 默认对key进行字典排序 auto res1 = object.emplace("three", 3); null.emplace("A", "a"); null.emplace("B", "b"); // the following call will not add an object, because there is already // a value stored at key "B" auto res2 = null.emplace("B", "c"); // print values std::cout << object << 'n'; // expect {"one":1,"three":3,"two":2} // 添加失败,返回值res1.second为false,成功则为true std::cout << *res1.first << " " << std::boolalpha << res1.second << 'n'; // 3 true std::cout << null << 'n';// expect {"A":"a","B":"b"} std::cout << *res2.first << " " << std::boolalpha << res2.second << 'n';// "b" false }



