readArray - multiple declarations

Function readArray

Reads an array and issues a callback for each entry.

void readArray(R) (
  ref R nodes,
  scope @safe void delegate() del
)
if (isJSONParserNodeInputRange!R);

Parameters

NameDescription
nodes An input range of JSON parser nodes
del The callback to invoke for each array entry

Example

auto j = parseJSONStream(q{
        [
            "foo",
            "bar"
        ]
    });

size_t i = 0;
j.readArray({
    auto value = j.readString();
    switch (i++) {
        default: assert(false);
        case 0: assert(value == "foo"); break;
        case 1: assert(value == "bar"); break;
    }
});

assert(j.empty);

Function readArray

Reads an array and returns a lazy range of parser node ranges.

auto auto readArray(R) (
  ref R nodes
) @system
if (isJSONParserNodeInputRange!R);

The given parser node range must point to a node of kind JSONParserNodeKind.arrayStart. Each of the returned sub ranges corresponds to the contents of a single array entry.

Parameters

NameDescription
nodes An input range of JSON parser nodes

Throws

A JSONException is thrown if the input range does not point to the start of an array.

Example

auto j = parseJSONStream(q{
        [
            "foo",
            "bar"
        ]
    });

size_t i = 0;
foreach (ref entry; j.readArray) {
    auto value = entry.readString;
    assert(entry.empty);
    switch (i++) {
        default: assert(false);
        case 0: assert(value == "foo"); break;
        case 1: assert(value == "bar"); break;
    }
}
assert(i == 2);