Tango JSON Parser: Accessing the members

Moritz Warning moritzwarning at web.de
Sun Aug 17 04:10:57 PDT 2008


On Sat, 16 Aug 2008 19:31:20 -0400, Benji Smith wrote:

> I've been trying out the new tango JSON parser, and the functionality
> for actually parsing the string is very easy to invoke. But I can't
> figure out, for the life of me, how to read the individual children of
> the resultant object hierarchy.
> 
> Here's what I've got:
> 
> module mymodule;
> 
> import tango.text.json.Json;
> 
> void main() {
> 
>    char[] json = `{"t": true}`;
> 
>    auto parser = new Json!(char);
> 
>    // "Error: identifier 'JsonValue' is not defined" JsonValue*
>    jsonValue = p.parse(json);
> 
>    // "Error: identifier 'JsonObject' is not defined" JsonObject
>    jsonObject = p.parse(json).toObject();
> 
>    // "Error: identifier 'Composite' is not defined" Composite composite
>    = p.parse(json).toObject();
> 
> }
> 
> I'm sure I'm missing something from my 'import' declarations, but I've
> tried adding "tango.text.json.JsonValue" or
> "tango.text.json.Json.JsonValue" or "tango.text.json.Json.Composite" and
> the compiler has not been happy with any of those (each of which is a
> struct or an alias defined within the Json class).
> 
> Has anyone else tinkered with the JSON stuff yet? Any ideas?
> 
> Thanks!
> 
> --benji

Use

auto value = p.parse(json);

or

Json!(char).Value value = p.parse(json);

or

Json!(char).JsonValue* value = p.parse(json);



More information about the Digitalmars-d-learn mailing list