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
(DataFlex) Swap JSON ObjectsDemonstrates how to swap two JSON objects within a JSON document. Note: This example requires Chilkat v9.5.0.76 or greater.
Use ChilkatAx-win32.pkg Procedure Test Handle hoJson Boolean iSuccess Integer iIndex1 Integer iIndex2 Variant vJsonSara Handle hoJsonSara String sTemp1 Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Set ComEmitCompact Of hoJson To False // Load the following JSON: // { // "petter": { // "DOB": "26/02/1986", // "gender": "male", // "country": "US" // }, // "Sara": { // "DOB": "13/05/1982", // "gender": "female", // "country": "FR" // }, // "Jon": { // "DOB": "19/03/1984", // "gender": "male", // "country": "UK" // } // } Get ComLoadFile Of hoJson "qa_data/json/people.json" To iSuccess // Assume success.. // Swap the positions of Jon and Sara. Get ComIndexOf Of hoJson "Jon" To iIndex1 Get ComIndexOf Of hoJson "Sara" To iIndex2 Get ComSwap Of hoJson iIndex1 iIndex2 To iSuccess // We have this now: Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // { // "petter": { // "DOB": "26/02/1986", // "gender": "male", // "country": "US" // }, // "Jon": { // "DOB": "19/03/1984", // "gender": "male", // "country": "UK" // }, // "Sara": { // "DOB": "13/05/1982", // "gender": "female", // "country": "FR" // } // } // To swap an inner member: Get ComObjectOf Of hoJson "Sara" To vJsonSara If (IsComObject(vJsonSara)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoJsonSara Set pvComObject Of hoJsonSara To vJsonSara End Get ComIndexOf Of hoJsonSara "DOB" To iIndex1 Get ComIndexOf Of hoJsonSara "country" To iIndex2 Get ComSwap Of hoJsonSara iIndex1 iIndex2 To iSuccess Send Destroy of hoJsonSara // We now have this: Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // { // "petter": { // "DOB": "26/02/1986", // "gender": "male", // "country": "US" // }, // "Jon": { // "DOB": "19/03/1984", // "gender": "male", // "country": "UK" // }, // "Sara": { // "country": "FR", // "gender": "female", // "DOB": "13/05/1982" // } // } End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.