IJsonArrayBuilder.Build

Syntax

Build: IJsonArray;

Description

The Build method returns the created JSON array.

Example

Sub UserProc;
Var
    NewJSON: IJsonObjectBuilder;
    VarArray: Array;
    JsonArray, SubArray: IJsonArrayBuilder;
    Doc: IJsonDocument;
Begin
    VarArray := New Variant[2];
    VarArray[0] := Integer.MaxValue;
    VarArray[1] := Double.MaxValue;
    SubArray := New JsonArrayBuilder.Create;
    SubArray.AddString("Subelement 1");
    SubArray.AddString("Subelement 2");
    // JSON array
    JsonArray := New JsonArrayBuilder.Create;
    JsonArray.AddBoolean(True);
    JsonArray.AddInteger(Integer.MaxValue);
    JsonArray.AddDouble(Double.MaxValue);
    JsonArray.AddNull;
    JsonArray.AddString("Text value");
    JsonArray.AddArray(VarArray);
    JsonArray.AddArrayBuilder(SubArray);
    // Create JSON structure
    NewJSON := New JsonObjectBuilder.Create;
    NewJSON.AddElement("Array", JsonArray.Build);
    // Save obtained JSON
    Doc := New JsonDocument.Create;
    Doc.RootElement := NewJSON.Build;
    Doc.WriteToFile("d:\Work\Json\array.json");
End Sub UserProc;

The specified function creates a new JSON structure, which will contain an array of various elements. The structure will be saved to the specified file.

See also:

IJsonArrayBuilder