diff --git a/api/adl_serializer/from_json/index.html b/api/adl_serializer/from_json/index.html index 6f485f124..3f8ff6f7f 100644 --- a/api/adl_serializer/from_json/index.html +++ b/api/adl_serializer/from_json/index.html @@ -29,22 +29,22 @@ { void from_json(const json& j, person& p) { - j.at("name").get_to(p.name); - j.at("address").get_to(p.address); - j.at("age").get_to(p.age); + j.at("name").get_to(p.name); + j.at("address").get_to(p.address); + j.at("age").get_to(p.age); } } // namespace ns int main() { json j; - j["name"] = "Ned Flanders"; - j["address"] = "744 Evergreen Terrace"; - j["age"] = 60; + j["name"] = "Ned Flanders"; + j["address"] = "744 Evergreen Terrace"; + j["age"] = 60; auto p = j.get<ns::person>(); - std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl; + std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl; }
Output:
Ned Flanders (60) lives in 744 Evergreen Terrace
The example below shows how a from_json is implemented as part of a specialization of the adl_serializer to realize the conversion of a non-default-constructible type.
#include <iostream>
@@ -74,17 +74,17 @@
{
static ns::person from_json(const json& j)
{
- return {j.at("name"), j.at("address"), j.at("age")};
+ return {j.at("name"), j.at("address"), j.at("age")};
}
- // Here's the catch! You must provide a to_json method! Otherwise, you
+ // Here's the catch! You must provide a to_json method! Otherwise, you
// will not be able to convert person to json, since you fully
// specialized adl_serializer on that type
static void to_json(json& j, ns::person p)
{
- j["name"] = p.name;
- j["address"] = p.address;
- j["age"] = p.age;
+ j["name"] = p.name;
+ j["address"] = p.address;
+ j["age"] = p.age;
}
};
} // namespace nlohmann
@@ -92,13 +92,13 @@
int main()
{
json j;
- j["name"] = "Ned Flanders";
- j["address"] = "744 Evergreen Terrace";
- j["age"] = 60;
+ j["name"] = "Ned Flanders";
+ j["address"] = "744 Evergreen Terrace";
+ j["age"] = 60;
auto p = j.get<ns::person>();
- std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
+ std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
}
Output:
Ned Flanders (60) lives in 744 Evergreen Terrace
-