D JSON (WAT?!)
Daniel Gibson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 24 08:59:52 PDT 2014
Am 24.07.2014 17:54, schrieb Pavel:
>
> Guess what, here's a new snippet:
>
> import std.stdio;
> import std.json;
>
> void main() {
> scope(failure) writeln("FaILED!!");
> string jsonStr = `{ "name": "1", "type": "r" }`;
> auto parsed = parseJSON(jsonStr).object;
> writeln("fail" in parsed);
> }
>
> Output is:
> null
>
> WAT?!
>
> Ofcourse, writing like:
>
> writeln(cast(bool)("fail" in parsed));
>
> Produces "false"... but why on earth boolean expression would output null?
>
> PS: Sorry, for such an emotional boom, I'm so frustrated right now.
Relax :-)
And see http://dlang.org/hash-map.html
"in" doesn't just return if something is in a map.
If it is, it returns a pointer to the value, otherwise null.
Thus null.
Cheers,
Daniel
More information about the Digitalmars-d-learn
mailing list