Jak to jest zrobione że do obiektu typu nlohmann::json jestem w stanie przypisać dowolny obiekt/strukturę ?
nlohmann::json nie zna budowy mojej struktury ,ale zaimplementowanie funkcji
void to_json(nlohmann::json& j, const struct_test1& p)
i już działa
struct struct_test1
{
int int1;
std::string string1;
};
void to_json(nlohmann::json& j, const struct_test1& p) {
j = nlohmann::json{{"int1", p.int1},
{"string1", p.string1}};
}
struct_test1 s1{1234,"12345");
nlohmann::json j = s1;
Chciałbym zrozumieć jak to działa !