TROJSONValue

Overview

The TROJSONValue class is created to represent a JSON item value that is stored inside structures such as a JSON object or a JSON array. This class is used internally by the JSON (de)serializer inside the TROJSONMessage class.
The TROJSONValue object is similar to the Variant data type in the sense that it has a number of properties As<Type> to read and write the value as various types with implicit data type conversion wherever possible. Depending on the compilation options, the code may raise exceptions or return nil or empty values in case the conversion is impossible. The default behavior is to raise exceptions.
Users are not required to deal with JSON directly, so they usually don't need to use this class.

Location

  • Unit: uROJSONParser.pas
  • Ancestry: TCollectionItem | TROJSONValue


 

constructor Create (TROJSONDataType)  reintroduce overload

Creates a new object instance and specifies the data type to store in it.

constructor Create(aType: TROJSONDataType)

Parameters:


constructor Create (TCollection)  overload override

Creates a new object instance and specifies the owning collection for it.

constructor Create(Collection: TCollection)

Parameters:


AsArray

Reads and writes the value as JSON array.

property AsArray: TROJSONArray read write

AsBoolean

Reads and writes the value as boolean.

property AsBoolean: Boolean read write

AsJSON

Returns object as JSON string

property AsJSON: JSON_String read

AsNumber

Reads and writes the value as number. The Variant data type is used to store the number.

property AsNumber: Variant read write

AsObject

Reads and writes the value as a JSON object.

property AsObject: TROJSONObject read write

AsString

Reads and writes the value as string.

property AsString: JSON_String read write

Clear

Empties the object. It will contain the value equivalent to NULL after this call.

procedure Clear

IntLoadFromStream  protected virtual

This internal method may be overriden in descendants to implement a specific object deserialization from the stream. Called by the LoadFromStream method.

procedure IntLoadFromStream(Source: TStream)

Parameters:

  • Source: Source stream

IsArray

Checks if value is embedded array

function IsArray: Boolean

IsBoolean

function IsBoolean: Boolean

IsNull

Checks if value is Null

function IsNull: Boolean

IsNumber

function IsNumber: Boolean

IsObject

function IsObject: Boolean

IsString

function IsString: Boolean

LoadFromStream

This internal method may be overriden in descendants to implement a specific object deserialization from the stream. Called by the LoadFromStream method.

procedure LoadFromStream(Source: TStream; aUTF8Stream: Boolean)

Parameters:

  • Source: Source stream
  • aUTF8Stream: When set to true, the object will use UTF-8 encoding when deserializing the data.

SaveToStream

Saves object to stream

procedure SaveToStream(Dest: TStream; aUTF8Stream: Boolean)

Parameters:

  • Dest: Dest stream
  • aUTF8Stream: Should be UTF-8 encoding used or not

SaveToStreamWithIndent

Saves object to stream with indent

procedure SaveToStreamWithIndent(Dest: TStream; aUTF8Stream: Boolean)

Parameters:

  • Dest: Dest stream
  • aUTF8Stream: Should be UTF-8 encoding used or not

SetAsNull

Sets the NULL value to the object, this is equivalent to the Clear call.

procedure SetAsNull

ValueType

Allows to get the data type (TROJSONDataType value) that is currently stored in the object.

property ValueType: TROJSONDataType read

VarValue

Reads and writes the value as a Variant.

property VarValue: Variant read write

 

AsArray

Reads and writes the value as JSON array.

property AsArray: TROJSONArray read write

AsBoolean

Reads and writes the value as boolean.

property AsBoolean: Boolean read write

AsJSON

Returns object as JSON string

property AsJSON: JSON_String read

AsNumber

Reads and writes the value as number. The Variant data type is used to store the number.

property AsNumber: Variant read write

AsObject

Reads and writes the value as a JSON object.

property AsObject: TROJSONObject read write

AsString

Reads and writes the value as string.

property AsString: JSON_String read write

ValueType

Allows to get the data type (TROJSONDataType value) that is currently stored in the object.

property ValueType: TROJSONDataType read

VarValue

Reads and writes the value as a Variant.

property VarValue: Variant read write

 

constructor Create (TROJSONDataType)  reintroduce overload

Creates a new object instance and specifies the data type to store in it.

constructor Create(aType: TROJSONDataType)

Parameters:


constructor Create (TCollection)  overload override

Creates a new object instance and specifies the owning collection for it.

constructor Create(Collection: TCollection)

Parameters:


Clear

Empties the object. It will contain the value equivalent to NULL after this call.

procedure Clear

IntLoadFromStream  protected virtual

This internal method may be overriden in descendants to implement a specific object deserialization from the stream. Called by the LoadFromStream method.

procedure IntLoadFromStream(Source: TStream)

Parameters:

  • Source: Source stream

IsArray

Checks if value is embedded array

function IsArray: Boolean

IsBoolean

function IsBoolean: Boolean

IsNull

Checks if value is Null

function IsNull: Boolean

IsNumber

function IsNumber: Boolean

IsObject

function IsObject: Boolean

IsString

function IsString: Boolean

LoadFromStream

This internal method may be overriden in descendants to implement a specific object deserialization from the stream. Called by the LoadFromStream method.

procedure LoadFromStream(Source: TStream; aUTF8Stream: Boolean)

Parameters:

  • Source: Source stream
  • aUTF8Stream: When set to true, the object will use UTF-8 encoding when deserializing the data.

SaveToStream

Saves object to stream

procedure SaveToStream(Dest: TStream; aUTF8Stream: Boolean)

Parameters:

  • Dest: Dest stream
  • aUTF8Stream: Should be UTF-8 encoding used or not

SaveToStreamWithIndent

Saves object to stream with indent

procedure SaveToStreamWithIndent(Dest: TStream; aUTF8Stream: Boolean)

Parameters:

  • Dest: Dest stream
  • aUTF8Stream: Should be UTF-8 encoding used or not

SetAsNull

Sets the NULL value to the object, this is equivalent to the Clear call.

procedure SetAsNull