Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Create a JSON Array of ObjectsDemonstrates how to create a JSON array of objects.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonArray, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var arr: HCkJsonArray; success: Boolean; obj: HCkJsonObject; begin arr := CkJsonArray_Create(); // Add an empty object at the 1st JSON array position. CkJsonArray_AddObjectAt(arr,0); // Get the object we just created. obj := CkJsonArray_ObjectAt(arr,0); CkJsonObject_UpdateString(obj,'Name','Otto'); CkJsonObject_UpdateInt(obj,'Age',29); CkJsonObject_UpdateBool(obj,'Married',False); CkJsonObject_Dispose(obj); // Add an empty object at the 2nd JSON array position. CkJsonArray_AddObjectAt(arr,1); obj := CkJsonArray_ObjectAt(arr,1); CkJsonObject_UpdateString(obj,'Name','Connor'); CkJsonObject_UpdateInt(obj,'Age',43); CkJsonObject_UpdateBool(obj,'Married',True); CkJsonObject_Dispose(obj); // Add an empty object at the 3rd JSON array position. CkJsonArray_AddObjectAt(arr,2); obj := CkJsonArray_ObjectAt(arr,2); CkJsonObject_UpdateString(obj,'Name','Ramona'); CkJsonObject_UpdateInt(obj,'Age',34); CkJsonObject_UpdateBool(obj,'Married',True); CkJsonObject_Dispose(obj); // Examine what we have: CkJsonArray_putEmitCompact(arr,False); Memo1.Lines.Add(CkJsonArray__emit(arr)); // The output is: // [ // { // "Name": "Otto", // "Age": 29, // "Married": false // }, // { // "Name": "Connor", // "Age": 43, // "Married": true // }, // { // "Name": "Ramona", // "Age": 34, // "Married": true // } // ] CkJsonArray_Dispose(arr); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.