AddObjectBuilder(Value: IJsonObjectBuilder): IJsonArrayBuilder;
Value. Created object.
The AddObjectBuilder method adds an object to the current created JSON array.
Sub UserProc;
Var
JsonArray: IJsonArrayBuilder;
NewJSON: IJsonObjectBuilder;
Doc: IJsonDocument;
Begin
JsonArray := New JsonArrayBuilder.Create;
// Create JSON structure
NewJSON := New JsonObjectBuilder.Create;
NewJSON.AddString("name", "Product 1");
NewJSON.AddInteger("price", 100);
NewJSON.AddDouble("weight", 1);
JsonArray.AddObjectBuilder(NewJSON);
NewJSON := New JsonObjectBuilder.Create;
NewJSON.AddString("name", "Product 2");
NewJSON.AddInteger("price", 200);
NewJSON.AddDouble("weight", 1.2);
JsonArray.AddObjectBuilder(NewJSON);
NewJSON := New JsonObjectBuilder.Create;
NewJSON.AddArrayBuilder("products", JsonArray);
// Save
Doc := New JsonDocument.Create;
Doc.RootElement := NewJSON.Build;
Doc.WriteToFile("d:\Work\Json\products.json");
End Sub UserProc;
The specified function creates a new JSON structure that will contain an elements array. Each array's element is a single JSON object with a set of elements. The structure will be saved to the specified file.
See also: