Add a placeholder for get<string>() is value is nullptr #4114
-
Currently I am doing something like this std::string myVal = myJson["myKey"] == nullptr ? "<empty>": myJson["myKey"].get<string>(); to make sure myVal is always a valid std::string myVal = myJson["myKey"].get<string>(if_null="<empty>"); |
Beta Was this translation helpful? Give feedback.
Answered by
gregmarr
Aug 30, 2023
Replies: 2 comments
-
Yes
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
alex-lt-kong
-
Just tried the method mentioned by @gregmarr . Works like a charm! In case anyone wonders, if we have a nested value, can achieve the same like below: std::string myVal = myJson.value("/myKey/alsoMyKey/moreKey"_json_pointer, "<empty>"); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes