Token
| Incremental processing is a low-level API which regards JSON as a sequence of tokens to be processed one by one. |
The JSON parser and generator use tokens to identify data types as well as errors.
All token-related types are located in the trial::protocol::json::token namespace,
which we will simply refer to as token below.
Tokens are located in the <trial/protocol/json/token.hpp> header.
|
Token constants
A token is represented by the token::code enumeration type with a constant for
each possible token or error state. This means that each error is represented
by its own enumerator constant.
Symbols
Working directly with token::code can be tedious.
Suppose you want to check if an error occurred, then you have to check if the
current token is one of the numerous error constants.
Each token::code enumerator has therefore been grouped into a more convenient
enumeration type called token::symbol that is better suited for normal
operation.
All token::code error constants have been grouped into the single
token::symbol::error constant, and we can now check for errors with a single
comparison.
|
Description |
|
True or false. |
|
Integer number. |
|
Floating-point number. |
|
String value. |
|
String key for associative array. |
|
No data. |
|
Start of an array. |
|
End of an array. |
|
Start of an associative array. |
|
End of an associative array. |
|
A context-specific separator. |
|
End of input or output buffer. |
|
Erroneous format. |
The symbol type will be the preferred manner to use tokens in the examples
throughout this documentation.
In fact, we are not even going to describe the token::code enumerator constants
here,.[1] because we are only interested in the
subset that contains the error codes and they are described in the section on
errors.
Categories
The symbol constants are grouped into the token::category enumeration type.
There are different categories of tokens:
|
Description |
|
Data tokens have a value associated with them, whose content can be retrieved. Examples of data tokens are booleans, numbers, and strings. |
|
Structural tokens wrap containers and separate items. |
|
The nullable token is a special case, because it can represent either a data token without and associated value or structural token without an associated container, such as a missing integer or a missing array. The nullable token is typeless. |
|
A status token indicates another condition. |
The following table shows which categories the the various symbols belong to.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token::code enumerator constants can be found in the reference documentation.