Skip to content
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 a list of class objects with json #1096

Closed
AncaMRG opened this issue May 17, 2018 · 4 comments
Closed

Serialize a list of class objects with json #1096

AncaMRG opened this issue May 17, 2018 · 4 comments
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@AncaMRG
Copy link

AncaMRG commented May 17, 2018

Hello,
I want to serialize a list which contains a class objects. How can I do that using json. For a list of regular types I understand, but when I try to use json j_list(listName), and the listName is a list of objects I receive some errors from to_json method and 'force_msvc_stacktrace'.

This is the code.

   std::list<Student>studentList;

// populate studentList with objects of Student class

string filename = "StudentList.json";
std::ofstream output(filename, std::ofstream::out);
json js_list(studentList);
output << js_list;
output.close();

What should I do to I make this work?
Thank you! :D

@gregmarr
Copy link
Contributor

gregmarr commented May 17, 2018

If you read the errors, it should tell you what you need to do.

You need a to_json function and a from_json function for the Student type. Instructions are in the README.

@AncaMRG
Copy link
Author

AncaMRG commented May 17, 2018

Thank you! :D

@nlohmann
Copy link
Owner

@AncaMRG Do you need further assistance or can I close this issue?

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label May 27, 2018
@AncaMRG
Copy link
Author

AncaMRG commented May 30, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants