TJSONObject.Create¶
Create a new instance of JSON object data.
Declaration¶
Source position: fpjson.pp line 713
public
constructor Create; reintroduce;
constructor Create(const Elements: Array of const); overload; overload;
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:
- If an odd number of arguments is passed
- an item where a name is expected does not contain a string
- A value contains an invalid class
- A value of a not recognized data type (pointer) is inserted in the elements
See also¶
| Name | Description |
|---|---|
| Add | Add a name, value to the object. |
| GetJSONInstanceType | JSON factory: Get the JSONData class types to use. |