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
(PureBasic) Create a JSON Array of ObjectsDemonstrates how to create a JSON array of objects.
IncludeFile "CkJsonArray.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() arr.i = CkJsonArray::ckCreate() If arr.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; Add an empty object at the 1st JSON array position. CkJsonArray::ckAddObjectAt(arr,0) ; Get the object we just created. obj.i = CkJsonArray::ckObjectAt(arr,0) CkJsonObject::ckUpdateString(obj,"Name","Otto") CkJsonObject::ckUpdateInt(obj,"Age",29) CkJsonObject::ckUpdateBool(obj,"Married",0) CkJsonObject::ckDispose(obj) ; Add an empty object at the 2nd JSON array position. CkJsonArray::ckAddObjectAt(arr,1) obj = CkJsonArray::ckObjectAt(arr,1) CkJsonObject::ckUpdateString(obj,"Name","Connor") CkJsonObject::ckUpdateInt(obj,"Age",43) CkJsonObject::ckUpdateBool(obj,"Married",1) CkJsonObject::ckDispose(obj) ; Add an empty object at the 3rd JSON array position. CkJsonArray::ckAddObjectAt(arr,2) obj = CkJsonArray::ckObjectAt(arr,2) CkJsonObject::ckUpdateString(obj,"Name","Ramona") CkJsonObject::ckUpdateInt(obj,"Age",34) CkJsonObject::ckUpdateBool(obj,"Married",1) CkJsonObject::ckDispose(obj) ; Examine what we have: CkJsonArray::setCkEmitCompact(arr, 0) Debug CkJsonArray::ckEmit(arr) ; The output is: ; [ ; { ; "Name": "Otto", ; "Age": 29, ; "Married": false ; }, ; { ; "Name": "Connor", ; "Age": 43, ; "Married": true ; }, ; { ; "Name": "Ramona", ; "Age": 34, ; "Married": true ; } ; ] CkJsonArray::ckDispose(arr) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.