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 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

 

constructor Create (TCollection)  overload override

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

constructor Create(Collection: TCollection)

Parameters:


constructor Create (TROJSONDataType)  reintroduce overload

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

constructor Create(aType: TROJSONDataType)

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

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

LoadFromStream

Deserializes the object from the stream.

procedure LoadFromStream(AStream: TStream; AUTF8Stream: boolean)

Parameters:

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

SaveToStream

Serializes the object to the stream.

procedure SaveToStream(AStream: TStream; AUTF8Stream: boolean)

Parameters:

  • AStream: Target stream
  • AUTF8Stream: When set to true, the object will use UTF-8 encoding when serializing the data.

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 write

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

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 write

VarValue

Reads and writes the value as a Variant.

property VarValue: Variant read write

 

constructor Create (TCollection)  overload override

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

constructor Create(Collection: TCollection)

Parameters:


constructor Create (TROJSONDataType)  reintroduce overload

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

constructor Create(aType: TROJSONDataType)

Parameters:


Clear

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

procedure Clear

LoadFromStream

Deserializes the object from the stream.

procedure LoadFromStream(AStream: TStream; AUTF8Stream: boolean)

Parameters:

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

SaveToStream

Serializes the object to the stream.

procedure SaveToStream(AStream: TStream; AUTF8Stream: boolean)

Parameters:

  • AStream: Target stream
  • AUTF8Stream: When set to true, the object will use UTF-8 encoding when serializing the data.

SetAsNull

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

procedure SetAsNull

Descendants