Sign in Join
FPDoc Onlineexperiment

TJSONObject.Create constructor

Member of TJSONObjectpublicIn unit fpJson

Create a new instance of JSON object data.

Declaration

pascal
constructor Create; reintroduce
constructor Create(const Elements: Array of const); overload

Arguments

Elements

Names and corresponding values to be added to the object.

Description

Create creates a new JSON object instance, and initializes the data with Elements. Elements is an array containing an even number of items, alternating a name and a value. The names must be strings, and the values are converted to various TJSONData instances. If a value is an instance of TJSONData, it is added to the object array as-is.

The data type of the inserted objects is determined from the type of data passed to it, with a natural mapping. A Nil pointer will be inserted as a TJSONNull value. The following gives an example:

Var
  O : TJSONObject;

begin
  O:=TJSONObject.Create(['Age',44,
                        'Firstname','Michael',
                        'Lastname','Van Canneyt']);

Errors

An EConvertError exception is raised in one of the following cases:

  1. If an odd number of arguments is passed
  2. an item where a name is expected does not contain a string
  3. A value contains an invalid class
  4. A value of a not recognized data type (pointer) is inserted in the elements

See also

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.