From 50a3f3b301467d69c86d98d977c5db82764bda89 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 24 Jan 2017 14:55:51 +0100 Subject: [PATCH] :memo: added nicer example --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dd54fe71..3d05dc33 100644 --- a/README.md +++ b/README.md @@ -457,9 +457,10 @@ namespace ns { }; } +ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; + // convert to JSON: copy each value into the JSON object json j; -ns::person p = createSomeone(); j["name"] = p.name; j["address"] = p.address; j["age"] = p.age; @@ -477,12 +478,19 @@ ns::person p { It works, but that's quite a lot of boilerplate... Hopefully, there's a better way: ```cpp -// person -> json -ns::person p = createPerson(); +// create a person +ns::person p {"Ned Flanders", "744 Evergreen Terrace", 60}; + +// conversion: person -> json json j = p; -// json -> person -auto p2 = j.get(); +std::cout << j << std::endl; +// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} + +// conversion: json -> person +ns::person p2 = j; + +// that's it assert(p == p2); ```