Created
September 27, 2020 21:40
-
-
Save dominique120/c50ae284e45436dc58626ab3608154df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <nlohmann/json.hpp> | |
class Client { | |
public: | |
// members | |
std::uint32_t ClientId; | |
std::string FirstName; | |
std::string LastNames; | |
std::string PrimaryAddress; | |
std::string SecondaryAddress; | |
std::string PrimaryPhone; | |
std::string SecondaryPhone; | |
std::string District; | |
}; | |
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Client, ClientId, FirstName, LastNames, PrimaryAddress, SecondaryAddress, | |
PrimaryPhone, SecondaryPhone, District) | |
int main() | |
{ | |
std::string json_raw = "{\ | |
\"District\": \"DIstrict 5\",\ | |
\"ClientId\": \"\",\ | |
\"FirstName\" : \"John\",\ | |
\"LastNames\" : \"Doe\",\ | |
\"PrimaryAddress\" :\"Street #25\",\ | |
\"PrimaryPhone\" : \"126845136\",\ | |
\"SecondaryAddress\" : \"\",\ | |
\"SecondaryPhone\" : \"985148954\"}"; | |
Client cl; | |
auto j = nlohmann::json::parse(json_raw); | |
from_json(j, cl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment