-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
questions regarding from_json #1226
Copy link
Copy link
Closed
Labels
kind: questionsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Description
Activity
Metadata
Metadata
Assignees
Labels
kind: questionsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
I have a problem where if I try to convert json to a class, and the class have std::optional members I need to always check if the keys exists in the json and only if they exists (in json) then I can capture their data, something like:
m_id = (j.find("ID") != j.end() && j.at("ID") != nullptr)? j.at("ID").getstd::string() : nullopt;
how can I avoid it?
is there a way to change 'get' j.at("ID").getstd::string() and return either nullopt and avoid asking if 'ID' exists and not nullptr?