Annotation of functions
ag0aep6g
anonymous at example.com
Thu Feb 22 13:17:42 UTC 2018
On 02/22/2018 12:54 PM, psychoticRabbit wrote:
> module test;
>
> import std.stdio, std.file, std.json;
>
> void main()
> {
> string myFile= "source.json"; // a file produced by: dmd -o- -X
> source.d
>
> string js = readText(myFile);
>
> JSONValue j = parseJSON( js[1..$-1] ); // why do I have to do this??
>
> writefln("%s = %s", j["kind"].str, j["name"].str);
> writefln("file = %s", j["file"].str);
>
> }
You don't have to remove the brackets. You just have to process the
result correctly. It's not an object but an array with an object as its
first element.
If you're only interested in the first module (e.g. because you know
that there is exactly one), you can use `j[0]["kind"]`, `j[0]["name"]`,
`j[0]["file"]`.
If you want to handle multiple modules, you can loop over the array:
----
foreach (size_t i, item; j)
/* It's a bit silly that `foreach (item; j)` doesn't work. */
{
/* ... use `item["kind"]` etc. here ... */
}
----
More information about the Digitalmars-d
mailing list