JsonParserIter

Members

Aliases

Token
alias Token = typeof(super).Token

Import the Token enum into this namespace

Enums

TokenClass
enum TokenClass

TokenClass enum "Other" is for tokens that stand for themselves

Functions

nesting
int nesting()

Returns the nesting level difference caused by the current token.

nextNamed
cstring nextNamed(cstring name, bool found)

Iterates over the json string looking for the named element and returning the value of the following element.

nextNamedBool
bool nextNamedBool(cstring name, bool found)

Iterates over the json string looking for the named element and returning the value of the following element if it is a boolean. If the value is not boolean the search continues.

nextNamedNumber
T nextNamedNumber(cstring name, bool found)

Iterates over the json string looking for the named element and returning the value of the following element if it is a number. If the value is not a number the search continues.

nextNamedObject
bool nextNamedObject(cstring name)

Iterates over the json string looking for the named object and halting iteration if it is found.

nextNamedString
cstring nextNamedString(cstring name, bool found)

Iterates over the json string looking for the named element and returning the value of the following element if it is a string. If the value is not a string the search continues.

nextType
Token nextType()

Steps to the next token in the current JSON content.

opApply
int opApply(int delegate(ref Token type, ref cstring value) dg)

'foreach' iteration over type/value pairs in the current content

opApply
int opApply(int delegate(ref Token type, ref cstring name, ref cstring value) dg)

'foreach' iteration over type/name/value triples in the current content.

opCall
typeof(this) opCall(cstring content)

Resets the instance and sets the input content (convenience wrapper for super.reset()).

skip
uint skip()

Skips the current member so that the next member is reached by a next() call or in the next 'foreach' iteration cycle. That is, - if the current token denotes an object or array beginning, to the corresponding object/array end token, - if the current token is a name, steps over the name, - if the current member is a value, does nothing.

token_class
TokenClass token_class()

Static variables

nestings
int[Token.max + 1] nestings;

Token nesting difference values

token_classes
TokenClass[Token.max + 1] token_classes;

Token to TokenClass association

type_description
istring[Token.max + 1] type_description;

Token type descriptions

Examples

alias JsonParserIter!(true) JsonParserIterWithNan;
alias JsonParserIter!(false) JsonParserIterNoNan;

bool found;
istring json = `{ "object": { "cost": 12.34, "sub": { "cost": 42 } } }`;

scope parser = new JsonParserIterNoNan();
parser.reset(json);

auto val = parser.nextNamed("cost", found);
test(found, "Boolean flag should be set to true");
test!("==")(val, "12.34"[]);

found = false;
auto uval = parser.nextNamedNumber!(uint)("cost", found);
test(found, "Boolean flag should be set to true");
test!("==")(uval, 42);

Meta