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
(Tcl) Create a JSON Array of ObjectsDemonstrates how to create a JSON array of objects.
load ./chilkat.dll set arr [new_CkJsonArray] # Add an empty object at the 1st JSON array position. CkJsonArray_AddObjectAt $arr 0 # Get the object we just created. # obj is a CkJsonObject set obj [CkJsonArray_ObjectAt $arr 0] CkJsonObject_UpdateString $obj "Name" "Otto" CkJsonObject_UpdateInt $obj "Age" 29 CkJsonObject_UpdateBool $obj "Married" 0 delete_CkJsonObject $obj # Add an empty object at the 2nd JSON array position. CkJsonArray_AddObjectAt $arr 1 set obj [CkJsonArray_ObjectAt $arr 1] CkJsonObject_UpdateString $obj "Name" "Connor" CkJsonObject_UpdateInt $obj "Age" 43 CkJsonObject_UpdateBool $obj "Married" 1 delete_CkJsonObject $obj # Add an empty object at the 3rd JSON array position. CkJsonArray_AddObjectAt $arr 2 set obj [CkJsonArray_ObjectAt $arr 2] CkJsonObject_UpdateString $obj "Name" "Ramona" CkJsonObject_UpdateInt $obj "Age" 34 CkJsonObject_UpdateBool $obj "Married" 1 delete_CkJsonObject $obj # Examine what we have: CkJsonArray_put_EmitCompact $arr 0 puts [CkJsonArray_emit $arr] # The output is: # [ # { # "Name": "Otto", # "Age": 29, # "Married": false # }, # { # "Name": "Connor", # "Age": 43, # "Married": true # }, # { # "Name": "Ramona", # "Age": 34, # "Married": true # } # ] delete_CkJsonArray $arr |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.