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
(C) Create a JSON Array of ObjectsDemonstrates how to create a JSON array of objects.
#include <C_CkJsonArray.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkJsonArray arr; BOOL success; HCkJsonObject obj; 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); printf("%s\n",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); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.