-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Serialization of struct object. #1877
Labels
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
Comments
You also need to copy the to_json/from_json functions from the example.
Von meinem iPhone gesendet
… Am 23.12.2019 um 11:04 schrieb AlexRos101 ***@***.***>:
Hi, nlohmann!
Thank you for your project.
I don't want to set the key and value manually.
So I have used the code below.
// create a person
ns::person p {"Ned Flanders", "744 Evergreen Terrace", 60};
// conversion: person -> json
json j = p;
std::cout << j << std::endl;
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
// conversion: json -> person
auto p2 = j.get<ns::person>();
// that's it
assert(p == p2);
But this code has some errors.
no suitable user-defined conversion from "ns::person" to "nlohmann::json" exists
no instance of overloaded function "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::get [with ObjectType=std::map, ArrayType=std::vector, StringType=std::string, BooleanType=bool, NumberIntegerType=int64_t, NumberUnsignedType=uint64_t, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer]" matches the argument list
How can I fix these errors?
I hope your help.
Thanks.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Hi! So there is no way to convert directly without to_json/from_json function? Thanks. |
No, you need to, at some point, tell the library how to read/write JSON for your type. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, nlohmann!
Thank you for your project.
I don't want to set the key and value manually.
So I have used the code below.
But this code has some errors.
How can I fix these errors?
I hope your help.
Thanks.
The text was updated successfully, but these errors were encountered: