Struct JsonParser.JsonValue
Represents a JSON value in the parsed data, including its children (for objects/arrays) and its position/length in the underlying stream.
Inherited Members
Namespace: TriLibCore.Utils
Assembly: TriLibCore.dll
Syntax
public struct JsonParser.JsonValue : IEnumerable<JsonParser.JsonValue>, IEnumerable
Constructors
JsonValue(JsonParser, int, int, JsonValueType)
Initializes a new instance of the JsonParser.JsonValue struct with the given parameters.
Declaration
public JsonValue(JsonParser jsonParser, int position, int valueLength, JsonParser.JsonValueType type)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonParser | jsonParser | The JsonParser used to read and interpret the underlying data. |
| int | position | The start position of this value in the stream. |
| int | valueLength | The length (in bytes) of this value in the stream. |
| JsonParser.JsonValueType | type | The JsonParser.JsonValueType representing this value. |
Properties
Count
Gets the total number of direct child values.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
JsonParser
Gets the JsonParser associated with this value.
Declaration
public JsonParser JsonParser { get; }
Property Value
| Type | Description |
|---|---|
| JsonParser |
Position
Gets or sets the position of this JSON value in the underlying stream.
Declaration
public int Position { get; }
Property Value
| Type | Description |
|---|---|
| int |
Type
Gets the JsonParser.JsonValueType for this value.
Declaration
public JsonParser.JsonValueType Type { get; }
Property Value
| Type | Description |
|---|---|
| JsonParser.JsonValueType |
Valid
Indicates whether this value is valid (i.e., has a non-zero length).
Declaration
public bool Valid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
ValueLength
Gets or sets the length (in bytes) of this value in the underlying stream.
Declaration
public int ValueLength { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AddChild(long, JsonValue, string)
Adds a child JsonParser.JsonValue to the current value.
Declaration
public void AddChild(long hash, JsonParser.JsonValue value, string key)
Parameters
| Type | Name | Description |
|---|---|---|
| long | hash | A computed hash of the key (if any). |
| JsonParser.JsonValue | value | The JsonParser.JsonValue to add as a child. |
| string | key | The optional string key associated with this child. |
AddOffset(int)
Adjusts the starting position of this value by the given offset, and reduces its length accordingly.
Declaration
public JsonParser.JsonValue AddOffset(int offset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | offset | The number of bytes to shift from the current position. |
Returns
| Type | Description |
|---|---|
| JsonParser.JsonValue | This JsonParser.JsonValue after the offset has been applied. |
CopyTo(char[])
Copies the bytes of this value into the specified buffer.
Declaration
public int CopyTo(char[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| char[] | buffer | The character array to receive the value's data. |
Returns
| Type | Description |
|---|---|
| int | The number of characters copied into |
GetByteEnumerator()
Returns an enumerator that can iterate through the bytes of this value in the underlying stream.
Declaration
public JsonParser.JsonValue.JsonByteEnumerator GetByteEnumerator()
Returns
| Type | Description |
|---|---|
| JsonParser.JsonValue.JsonByteEnumerator | A JsonParser.JsonValue.JsonByteEnumerator for this value. |
GetCharEnumerator()
Returns an enumerator that can iterate through the characters of this value in the underlying stream.
Declaration
public JsonParser.JsonValue.JsonCharEnumerator GetCharEnumerator()
Returns
| Type | Description |
|---|---|
| JsonParser.JsonValue.JsonCharEnumerator | A JsonParser.JsonValue.JsonCharEnumerator for this value. |
GetChildAtIndex(int)
Retrieves the child JsonParser.JsonValue at the specified index.
Declaration
public JsonParser.JsonValue GetChildAtIndex(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the child to retrieve. |
Returns
| Type | Description |
|---|---|
| JsonParser.JsonValue | The child JsonParser.JsonValue at |
GetChildWithKey(long)
Retrieves the child JsonParser.JsonValue for the given key hash, returning its first child (value). This is typically used when the child is itself an object or a single value.
Declaration
public JsonParser.JsonValue GetChildWithKey(long hash)
Parameters
| Type | Name | Description |
|---|---|---|
| long | hash | The hash of the key for which to retrieve the child. |
Returns
| Type | Description |
|---|---|
| JsonParser.JsonValue | The first child JsonParser.JsonValue associated with the key hash; otherwise, a default JsonParser.JsonValue if not found. |
GetEnumerator()
Returns an enumerator that iterates through this JsonParser.JsonValue's children.
Declaration
public IEnumerator<JsonParser.JsonValue> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<JsonParser.JsonValue> | An IEnumerator<T> for the child JsonParser.JsonValue objects. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
GetStringValue(JsonParser, long, int)
Extracts a string value from the underlying stream for the specified
position and length.
Declaration
public static string GetStringValue(JsonParser jsonParser, long position, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonParser | jsonParser | The JsonParser that manages the stream. |
| long | position | The position in the stream at which the string value begins. |
| int | length | The length (in bytes) of the string. |
Returns
| Type | Description |
|---|---|
| string | The string read from the stream, or an empty string if an error occurs. |
ToString()
Converts this value to its string representation by reading data from the underlying stream.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that represents the contents of this JSON value. |