Replies: 4 comments 2 replies
-
Your code should be like this: // JSON example
// {
// "name": "abc",
// "age": 15
// };
void foo(string s)
{
}
// Ignore my spacing please, thx
json j;
if(j["name"].is_string() == true)
{
foo( j["name"].get<std::string>() );
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
@nlohmann @PatchByte Thanks, it works well. But it does not work to pass params by reference, e.g.,
Compiler(Clang 13.0 in OSX M1) error message
There are alternatives I guess, like pass param in |
Beta Was this translation helpful? Give feedback.
1 reply
-
Or declare `void foo2 (const string &s)`.
…On Sat, Aug 26, 2023 at 3:45 AM Niels Lohmann ***@***.***> wrote:
Use get_ref to get a reference to the string.
—
Reply to this email directly, view it on GitHub
<#4118 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANQEZUYC2VDZECX6FEVXKDXXGSSZANCNFSM6AAAAAA3ZEOAKI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
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
-
Hi,
Is is possible to cast a JSON value to certain types?
An alternative will be ok, but it's more verbose
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions