mirror of
https://github.com/nlohmann/json.git
synced 2024-12-16 06:59:04 +08:00
504012a3db
As <iostream> is not included in json.hpp any more, all code examples need to include <iostream> now.
32 lines
766 B
C++
32 lines
766 B
C++
#include <iostream>
|
|
#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
|
|
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';
|
|
std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n';
|
|
|
|
std::cout << null << '\n';
|
|
std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n';
|
|
}
|