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
(Unicode C) Create a JSON Array of ObjectsDemonstrates how to create a JSON array of objects.
#include <C_CkJsonArrayW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkJsonArrayW arr; BOOL success; HCkJsonObjectW obj; arr = CkJsonArrayW_Create(); // Add an empty object at the 1st JSON array position. CkJsonArrayW_AddObjectAt(arr,0); // Get the object we just created. obj = CkJsonArrayW_ObjectAt(arr,0); CkJsonObjectW_UpdateString(obj,L"Name",L"Otto"); CkJsonObjectW_UpdateInt(obj,L"Age",29); CkJsonObjectW_UpdateBool(obj,L"Married",FALSE); CkJsonObjectW_Dispose(obj); // Add an empty object at the 2nd JSON array position. CkJsonArrayW_AddObjectAt(arr,1); obj = CkJsonArrayW_ObjectAt(arr,1); CkJsonObjectW_UpdateString(obj,L"Name",L"Connor"); CkJsonObjectW_UpdateInt(obj,L"Age",43); CkJsonObjectW_UpdateBool(obj,L"Married",TRUE); CkJsonObjectW_Dispose(obj); // Add an empty object at the 3rd JSON array position. CkJsonArrayW_AddObjectAt(arr,2); obj = CkJsonArrayW_ObjectAt(arr,2); CkJsonObjectW_UpdateString(obj,L"Name",L"Ramona"); CkJsonObjectW_UpdateInt(obj,L"Age",34); CkJsonObjectW_UpdateBool(obj,L"Married",TRUE); CkJsonObjectW_Dispose(obj); // Examine what we have: CkJsonArrayW_putEmitCompact(arr,FALSE); wprintf(L"%s\n",CkJsonArrayW_emit(arr)); // The output is: // [ // { // "Name": "Otto", // "Age": 29, // "Married": false // }, // { // "Name": "Connor", // "Age": 43, // "Married": true // }, // { // "Name": "Ramona", // "Age": 34, // "Married": true // } // ] CkJsonArrayW_Dispose(arr); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.