IJsonObjectBuilder.AddObjectBuilder

Syntax

AddObjectBuilder(Property_: String; Value: IJsonObjectBuilder): IJsonObjectBuilder;

AddObjectBuilder(Property_: String; Value: Prognoz.Platform.Interop.ForeSystem.IJsonObjectBuilder): Prognoz.Platform.Interop.ForeSystem.IJsonObjectBuilder;

Parameters

Property_. Element name.

Value. Created JSON object.

Description

The AddObjectBuilder method adds an element with JSON object as a value.

Example

Add links to the ForeSystem (for the Fore.NET example) system assembly.

Sub UserProc;
Var
    NewJSON, SubJSON: IJsonObjectBuilder;
    Doc: IJsonDocument;
Begin
    
// Create JSON structure
    NewJSON := New JsonObjectBuilder.Create;
    SubJSON := 
New JsonObjectBuilder.Create;
    SubJSON.AddInteger(
"price"100);
    SubJSON.AddDouble(
"weight"1);
    NewJSON.AddObjectBuilder(
"Product 1", SubJSON);
    SubJSON := 
New JsonObjectBuilder.Create;
    SubJSON.AddInteger(
"price"200);
    SubJSON.AddDouble(
"weight"1.2);
    NewJSON.AddObjectBuilder(
"Product 2", SubJSON);
    
// Save
    Doc := New JsonDocument.Create;
    Doc.Root := NewJSON.Build;
    Doc.WriteToFile(
"d:\Work\Json\info.json");
End Sub UserProc;

Imports Prognoz.Platform.Interop.ForeSystem;

Sub UserProc();
Var
    NewJSON, SubJSON: JsonObjectBuilder = 
New JsonObjectBuilderClass();
    Doc: IJsonDocument = 
New JsonDocumentClass();
Begin
    
// Create JSON structure
    SubJSON.AddInteger("price"100);
    SubJSON.AddDouble(
"weight"1);
    NewJSON.AddObjectBuilder(
"Product 1", SubJSON);
    SubJSON := 
New JsonObjectBuilderClass();
    SubJSON.AddInteger(
"price"200);
    SubJSON.AddDouble(
"weight"1.2);
    NewJSON.AddObjectBuilder(
"Product 2", SubJSON);
    
// Save
    Doc.Root := NewJSON.Build();
    Doc.WriteToFile(
"d:\Work\Json\info.json", JsonFormatOptions.jfoDefault);
End Sub;

The specified function creates a new JSON structure, to which elements with a set of child objects will be added. The structure will be saved to the specified file.

See also:

IJsonObjectBuilder