Event driven stream JSON parser
OperationsCode example:
stream := System.IO.Filesystem.FileReader->ReadFile(args[0]);
parser := Data.JSON.Stream.JsonStreamParser->New(stream);
if(parser->GetNextElement("person") & parser->GetNextElement("age") & parser->GetNextElement()) {
parser->GetValue()->PrintLine();
};
parser->Reset();
while(parser->GetType() <> JsonStreamParser->JsonStreamType->END & parser->GetType() <> JsonStreamParser->JsonStreamType->ERROR) {
if(parser->GetType() = JsonStreamParser->JsonStreamType->OBJECT_LIT) {
if(parser->GetNextElement()) {
parser->GetValue()->PrintLine();
};
};
};
Constructor
New()
Constructor
New(stream:String)
Name | Type | Description |
---|---|---|
stream | String | input stream |
Get the last error message
method : public : GetLastError() ~ String
Type | Description |
---|---|
String | last error message |
Gets the current stream document tree level. 0 is the document root.
method : public : GetLevel() ~ Int
Type | Description |
---|---|
Int | current stream document tree level |
Gets the next element that matches the object literal name
method : public : native : GetNextElement(value:String) ~ Bool
Name | Type | Description |
---|---|---|
value | String | value to match |
Type | Description |
---|---|
Bool | true if element match, false otherwise |
Gets the next element
method : public : GetNextElement() ~ Bool
Type | Description |
---|---|
Bool | true if successful match, false otherwise |
Gets the nth element per offset
method : public : native : GetNextElement(offset:Int) ~ Bool
Name | Type | Description |
---|---|---|
offset | Int | offset from current position |
Type | Description |
---|---|
Bool | true if element match, false otherwise |
Gets the current stream type
method : public : GetType() ~ JsonStreamParser->JsonStreamType
Type | Description |
---|---|
JsonStreamParser->JsonStreamType | current stream type |
Gets the current stream type name
method : public : GetTypeName() ~ String
Type | Description |
---|---|
String | current stream type name |
Gets the current stream value
method : public : GetValue() ~ String
Type | Description |
---|---|
String | current stream value |
Checks to see the element pointer can be advanced
method : public : More() ~ Bool
Type | Description |
---|---|
Bool | true if pointer can be advanced, false otherwise |
Advances the element pointer
method : public : Next() ~ Nil
Reset stream cursor to the beginning
method : public : Reset() ~ Nil
Reset stream cursor to the beginning and reset buffer
method : public : Reset(stream:String) ~ Nil
Name | Type | Description |
---|---|---|
stream | String | input stream buffer |