1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-16 18:41:53 +03:00

Documentation change (#3672)

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
This commit is contained in:
Niels Lohmann
2022-08-05 19:51:39 +02:00
committed by GitHub
parent 9e1a7c85e3
commit 7b6cf5918b
65 changed files with 582 additions and 302 deletions

32
docs/examples/to_json.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace ns
{
// a simple struct to model a person
struct person
{
std::string name;
std::string address;
int age;
};
} // namespace ns
namespace ns
{
void to_json(json& j, const person& p)
{
j = json{ {"name", p.name}, {"address", p.address}, {"age", p.age} };
}
} // namespace ns
int main()
{
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
json j = p;
std::cout << j << std::endl;
}