Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Delphi ActiveX) Merge SP-API JSON Order ArraysSee more Amazon SP-API ExamplesDemonstrates how to merge JSON arrays for the case of Amazon SP-API orders.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB; ... procedure TForm1.Button1Click(Sender: TObject); var a1: WideString; a2: WideString; success: Integer; json1: TChilkatJsonObject; json2: TChilkatJsonObject; jarr1: IChilkatJsonArray; jarr2: IChilkatJsonArray; i: Integer; numOrders: Integer; jOrder: IChilkatJsonObject; begin // Batch 1 File a1 := '{"payload": {"Orders": [{"AmazonOrderId": "1","OrderStatus": "Unshipped"},{"AmazonOrderId": "2","OrderStatus": "Unshipped"}]}'; // Batch 2 File a2 := '{"payload": {"Orders": [{"AmazonOrderId": "3","OrderStatus": "Unshipped"},{"AmazonOrderId": "4","OrderStatus": "Unshipped"}]}'; // Required Merged File // {"payload": {"Orders": [{"AmazonOrderId": "1","OrderStatus": "Unshipped"},{"AmazonOrderId": "2","OrderStatus": "Unshipped"},{"AmazonOrderId": "3","OrderStatus": "Unshipped"},{"AmazonOrderId": "4","OrderStatus": "Unshipped"}]} success := 1; json1 := TChilkatJsonObject.Create(Self); json1.Load(a1); json2 := TChilkatJsonObject.Create(Self); json2.Load(a2); // We're going to add the order records from json2 to json1. jarr1 := json1.ArrayOf('payload.Orders'); jarr2 := json2.ArrayOf('payload.Orders'); i := 0; numOrders := jarr2.Size; while (i < numOrders) do begin jOrder := jarr2.ObjectAt(i); // Assuming non-null return... jarr1.AddObjectCopyAt(-1,jOrder); i := i + 1; end; // Show the merged JSON. json1.EmitCompact := 0; Memo1.Lines.Add(json1.Emit()); // Result: // { // "payload": { // "Orders": [ // { // "AmazonOrderId": "1", // "OrderStatus": "Unshipped" // }, // { // "AmazonOrderId": "2", // "OrderStatus": "Unshipped" // }, // { // "AmazonOrderId": "3", // "OrderStatus": "Unshipped" // }, // { // "AmazonOrderId": "4", // "OrderStatus": "Unshipped" // } // ] // } // } end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.