@JsonCreate
Syntax
@JsonCreate;
@JsonCreate(JSONTYPE);
Description
This @Function creates a new empty JSON structure and returns a VSPECHJSON (HJS) handle.
If the function is called without parameters, a JSON object is created by default.
If the optional JSONTYPE parameter is set to "Array", a JSON array is created instead.
The returned handle can subsequently be used with functions such as @JsonAdd, @JsonGet, or @JsonSerialize.
A returned handle must be released with @JsonRelease after it is no longer needed.
TEXT JSONTYPE:
Optional type of the JSON structure to create.
"Object" JSON-Object {}
"Array" JSON-Array []
The value is case-insensitive. If JSONTYPE is omitted, a JSON object is created.
With the current implementation, any text value other than "Array" also results in a JSON object being created.
As return value, the @Function returns @ERROR on failure; otherwise, it returns a VSPECHJSON (HJS) handle to the newly created JSON structure.
Example: @JsonCreate
HJSON:=@JsonCreate;
@JsonAdd(HJSON;"Max Mustermann";"Name");
@JsonAdd(HJSON;42;"Age");
JSONTEXT:=@JsonSerialize(HJSON);
@JsonRelease(HJSON);
The example first creates an empty JSON object and then adds two values.
The resulting JSON structure is:
{"Name":"Max Mustermann","Age":42.0}
The JSON object is then converted to its textual representation using @JsonSerialize, and the generated VSPECHJSON (HJS) handle is released with @JsonRelease.
Example: Beispiel: @JsonCreate("Array");
HJSON:=@JsonCreate("Array");
@JsonAdd(HJSON;"Text1");
@JsonAdd(HJSON;"Text2");
@JsonAdd(HJSON;100);
JSONTEXT:=@JsonSerialize(HJSON);
@JsonRelease(HJSON);
The example creates an empty JSON array and then adds three elements.
The resulting JSON structure is:
["Text1","Text2",100.0]
The generated VSPECHJSON (HJS) handle is released with @JsonRelease after use.
Note : This text was machine-translated and may contain inaccuracies.
