TROJSONObject

Overview

The TROJSONObject class is created to represent a JSON object, which is an unordered set of name/value pairs. This class is used internally by the JSON (de)serializer inside the TROJSONMessage class.
Users are not required to deal with JSON directly, so there is no need to use this class.

Location

 

constructor Create

Creates a new instance.

constructor Create

Add

Adds a new empty name/value pair (property) object to the collection and returns it for further processing.

function Add: TROJSONProperty

AddArrayProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddArrayProperty(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

AddBooleanProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddBooleanProperty(const aName: JSON_String; const aValue: Boolean): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AddNullProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddNullProperty(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

AddNumberProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddNumberProperty(const aName: JSON_String; const aValue: Variant): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AddObjectProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddObjectProperty(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

AddStringProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddStringProperty(const aName: JSON_String; const aValue: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AddVariantProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddVariantProperty(const aName: JSON_String; const aValue: Variant): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AsJSON

Returns object as JSON string

property AsJSON: JSON_String read

FindItem

Internal method responsible for parsing and loading the JSON object from the stream.

function FindItem(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

GetArrayItemByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetArrayItemByName(const aName: JSON_String; aCreate: Boolean): TROJSONArray

Parameters:

  • aName: Source stream
  • aCreate: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

GetBooleanValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetBooleanValueByName(const aName: JSON_String): Boolean

Parameters:

  • aName: Source stream

GetItems  protected

The Items property read accessor function.

function GetItems(Index: Integer): TROJSONProperty

Parameters:

  • Index:

GetNumberValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetNumberValueByName(const aName: JSON_String): Variant

Parameters:

  • aName: Source stream

GetObjectItemByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetObjectItemByName(const aName: JSON_String; aCreate: Boolean): TROJSONObject

Parameters:

  • aName: Source stream
  • aCreate: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

GetStringValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetStringValueByName(const aName: JSON_String): JSON_String

Parameters:

  • aName: Source stream

GetVariantValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetVariantValueByName(const aName: JSON_String): Variant

Parameters:

  • aName: Source stream

IndexOf

Internal method responsible for parsing and loading the JSON object from the stream.

function IndexOf(const aName: JSON_String): Integer

Parameters:

  • aName: Source stream

IntLoadFromStream  protected

Internal method responsible for parsing and loading the JSON object from the stream.

procedure IntLoadFromStream(Source: TStream)

Parameters:

  • Source: Source stream

ItemByName

Internal method responsible for parsing and loading the JSON object from the stream.

function ItemByName(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

Items

Provides access to the name/value pairs that the JSON object consists of by index. The inherited Count property is used to get the pairs count.

property Items[Index: Integer]: TROJSONProperty read write

LoadFromStream

Internal method responsible for parsing and loading the JSON object from the stream.

procedure LoadFromStream(Source: TStream; aUTF8Stream: Boolean)

Parameters:

  • Source: Source stream
  • aUTF8Stream: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

RemoveEmptyProperties

procedure RemoveEmptyProperties(aRecursive: Boolean)

Parameters:

  • aRecursive:

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: If set to true, the stream is assumed to have UTF-8 encoded data

SetItems  protected

The Items property write accessor function.

procedure SetItems(Index: Integer; const Value: TROJSONProperty)

Parameters:

  • Index:
  • Value:

Sort

procedure Sort(aComparer: TROJSONPropertyCompare)

Parameters:

  • aComparer:

 

AsJSON

Returns object as JSON string

property AsJSON: JSON_String read

Items

Provides access to the name/value pairs that the JSON object consists of by index. The inherited Count property is used to get the pairs count.

property Items[Index: Integer]: TROJSONProperty read write

 

constructor Create

Creates a new instance.

constructor Create

Add

Adds a new empty name/value pair (property) object to the collection and returns it for further processing.

function Add: TROJSONProperty

AddArrayProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddArrayProperty(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

AddBooleanProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddBooleanProperty(const aName: JSON_String; const aValue: Boolean): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AddNullProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddNullProperty(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

AddNumberProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddNumberProperty(const aName: JSON_String; const aValue: Variant): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AddObjectProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddObjectProperty(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

AddStringProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddStringProperty(const aName: JSON_String; const aValue: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

AddVariantProperty

Internal method responsible for parsing and loading the JSON object from the stream.

function AddVariantProperty(const aName: JSON_String; const aValue: Variant): TROJSONProperty

Parameters:

  • aName: Source stream
  • aValue: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

FindItem

Internal method responsible for parsing and loading the JSON object from the stream.

function FindItem(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

GetArrayItemByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetArrayItemByName(const aName: JSON_String; aCreate: Boolean): TROJSONArray

Parameters:

  • aName: Source stream
  • aCreate: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

GetBooleanValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetBooleanValueByName(const aName: JSON_String): Boolean

Parameters:

  • aName: Source stream

GetItems  protected

The Items property read accessor function.

function GetItems(Index: Integer): TROJSONProperty

Parameters:

  • Index:

GetNumberValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetNumberValueByName(const aName: JSON_String): Variant

Parameters:

  • aName: Source stream

GetObjectItemByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetObjectItemByName(const aName: JSON_String; aCreate: Boolean): TROJSONObject

Parameters:

  • aName: Source stream
  • aCreate: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

GetStringValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetStringValueByName(const aName: JSON_String): JSON_String

Parameters:

  • aName: Source stream

GetVariantValueByName

Internal method responsible for parsing and loading the JSON object from the stream.

function GetVariantValueByName(const aName: JSON_String): Variant

Parameters:

  • aName: Source stream

IndexOf

Internal method responsible for parsing and loading the JSON object from the stream.

function IndexOf(const aName: JSON_String): Integer

Parameters:

  • aName: Source stream

IntLoadFromStream  protected

Internal method responsible for parsing and loading the JSON object from the stream.

procedure IntLoadFromStream(Source: TStream)

Parameters:

  • Source: Source stream

ItemByName

Internal method responsible for parsing and loading the JSON object from the stream.

function ItemByName(const aName: JSON_String): TROJSONProperty

Parameters:

  • aName: Source stream

LoadFromStream

Internal method responsible for parsing and loading the JSON object from the stream.

procedure LoadFromStream(Source: TStream; aUTF8Stream: Boolean)

Parameters:

  • Source: Source stream
  • aUTF8Stream: If the data in the stream is UTF-8 encoded, this parameter should be set to true, otherwise to false.

RemoveEmptyProperties

procedure RemoveEmptyProperties(aRecursive: Boolean)

Parameters:

  • aRecursive:

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: If set to true, the stream is assumed to have UTF-8 encoded data

SetItems  protected

The Items property write accessor function.

procedure SetItems(Index: Integer; const Value: TROJSONProperty)

Parameters:

  • Index:
  • Value:

Sort

procedure Sort(aComparer: TROJSONPropertyCompare)

Parameters:

  • aComparer: