[Overview][Constants][Types][Classes][Procedures and functions][Index] Reference for unit 'fpjson' (#fcl)

TJSONObject.Create

Create a new instance of JSON object data.

Declaration

Source position: fpjson.pp line 643

public constructor TJSONObject.Create;

constructor TJSONObject.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

Add

  

Add a name, value to the object

GetJSONInstanceType

  

JSON factory: Get the JSONData class types to use


Documentation generated on: Jun 23 2021