-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize dynamic array #1879
Comments
Use std::vector<std::string> emails
Il mar 24 dic 2019, 08:17 AlexRos101 <notifications@github.com> ha scritto:
… Hi nlohmann!
Thank you for your project.
I have a question.
I want to serialize a dynamic array. The code is like below.
struct person {
std::string name;
std::string address;
int age;
std::string *emails; // this is a dynamic array of emails which the person has.
};
How can I solve this problem?
Thanks.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1879?email_source=notifications&email_token=AE63RKSVH76XQOCOKQ27FPLQ2GZPTA5CNFSM4J63QGK2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICOTZCQ>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE63RKXD5OCHNBZYIELLVWLQ2GZPTANCNFSM4J63QGKQ>
.
|
Hi frenzisys! Thank you for your reply. In that case, I can implement from_json function. Can you send me to_json function in the case of using std::vector? Thanks. |
|
The example is very simple: namespace ns {
struct person {
std::string name;
std::string address;
int age;
std::vector<std::string> emails; // this is a dynamic array of emails which the person has.
};
void to_json(json& j, const person& p) {
j = json{{"name", p.name}, {"address", p.address}, {"age", p.age}, {"emails", p.emails}};
}
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("emails").get_to(p.emails);
}
} // namespace ns I think this issue could be closed. |
Hi nlohmann!
Thank you for your project.
I have a question.
I want to serialize a dynamic array. The code is like below.
How can I solve this problem?
Thanks.
The text was updated successfully, but these errors were encountered: