D JSON (WAT?!)
Pavel via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 24 08:45:08 PDT 2014
On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote:
> On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote:
>> On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote:
>>> On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote:
>>>> Ok, let me start with the sample code:
>>>>
>>>> import std.stdio;
>>>> import std.json;
>>>>
>>>> void main() {
>>>> scope(failure) writeln("FaILED!!");
>>>> string jsonStr = `{ "name": "1", "type": "r" }`;
>>>> auto parsed = parseJSON(jsonStr);
>>>> string s = parsed["fail"].str;
>>>> writeln(s == "");
>>>> writeln(s is null);
>>>> writeln(s);
>>>> }
>>>>
>>>> Running "rdmd app.d" doesn't produce any output.
>>>> Can anyone explain such a behavior???
>>>>
>>>>
>>>> PS: Running dmd v2.065 on Linux x64.
>>>
>>> It's a bug in std.json (you should get a segfault, not no
>>> output at all)
>>>
>>> It is fixed now and I'm pretty sure it will be in 2.066
>>>
>>> std.json has been improved a lot, but I would still recommend
>>> using http://vibed.org/api/vibe.data.json/ instead
>>
>> perhaps "bug" is too strong a word, but it was a deficiency
>> that is now corrected. You will get an exception thrown now
>> and everything should work how you expect.
>
> Maybe. But still it's not the way I expect, any time you check
> for non-existing property you must consider exception, which is
> very heavy to deal with in such a situation. I'd rather expect
> to get null, whenever I try to fetch non-existing property, and
> not an exception.
>
> That's purely my point, and I don't claim to be right in this
> way. It's up to Phobos maintainers to decide how to reprent
> JSON parsing results.
Also that's why you just can't write:
writeln("fail" in parsed);
As JSONValue is just a wrapper: non-native, non-intuitive.
More information about the Digitalmars-d-learn
mailing list