mirror of
https://github.com/nlohmann/json.git
synced 2024-12-15 14:39:02 +08:00
22 lines
615 B
C++
22 lines
615 B
C++
#include <json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
int main()
|
|
{
|
|
// create JSON values
|
|
json j_array = {"alpha", "bravo", "charly", "delta", "easy"};
|
|
json j_number = 42;
|
|
json j_object = {{"one", "eins"}, {"two", "zwei"}};
|
|
|
|
// create copies using iterators
|
|
json j_array_range(j_array.begin() + 1, j_array.end() - 2);
|
|
json j_number_range(j_number.begin(), j_number.end());
|
|
json j_object_range(j_object.begin(), j_object.find("two"));
|
|
|
|
// serialize the values
|
|
std::cout << j_array_range << '\n';
|
|
std::cout << j_number_range << '\n';
|
|
std::cout << j_object_range << '\n';
|
|
}
|