How to check if JSONValue of type object has a key?
Marco Leise via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 6 17:28:19 PDT 2015
Am Tue, 06 Oct 2015 21:39:28 +0000
schrieb Fusxfaranto <fusxfaranto at gmail.com>:
> Additionally, just like associative arrays, if you need to access
> the value, you can get a pointer to it with the in operator (and
> if the key doesn't exist, it will return a null pointer).
>
> const(JSONValue)* p = "key" in root;
> if (p)
> {
> // key exists, do something with p or *p
> }
> else
> {
> // key does not exist
> }
And you could go further and write
if (auto p = "key" in root)
{
// key exists, do something with p or *p
}
else
{
// key does not exist
}
--
Marco
More information about the Digitalmars-d-learn
mailing list