Skip to content

Instantly share code, notes, and snippets.

@dominique120
Created September 27, 2020 21:40
Show Gist options
  • Save dominique120/c50ae284e45436dc58626ab3608154df to your computer and use it in GitHub Desktop.
Save dominique120/c50ae284e45436dc58626ab3608154df to your computer and use it in GitHub Desktop.
#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