BDE 4.14.0 Production release
|
Provide a tokenizer for extracting JSON data from a streambuf
.
streambuf
This component provides a class, baljsn::Tokenizer
, that traverses data stored in a bsl::streambuf
one node at a time and provides clients access to the data associated with that node, including its type and data value. Client code can use the reset
function to associate a bsl::streambuf
containing JSON data with a tokenizer object and then call the advanceToNextToken
function to extract individual data values.
This class
was created to be used by other components in the baljsn
package and in most cases clients should use the baljsn_decoder component instead of using this class
.
On malformed JSON, tokenization may fail before the end of input is reached, but not all such errors are detected. In particular, callers should check that closing brackets and braces match opening ones.
This section illustrates intended use of this component.
For this example, we will use baljsn::Tokenizer
to read each node in a JSON document and populate a simple Employee
object.
First, we will define the JSON data that the tokenizer will traverse over:
Next, we will construct populate a streambuf
with this data:
Then, we will create a baljsn::Tokenizer
object and associate the above streambuf with it:
Next, we will create an address record type and object.
Then, we will traverse the JSON data one node at a time:
Finally, we will verify that the address
aggregate has the correct values: