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
(Visual Basic 6.0) Merge SP-API JSON Order ArraysSee more Amazon SP-API ExamplesDemonstrates how to merge JSON arrays for the case of Amazon SP-API orders.
' Batch 1 File Dim a1 As String a1 = "{""payload"": {""Orders"": [{""AmazonOrderId"": ""1"",""OrderStatus"": ""Unshipped""},{""AmazonOrderId"": ""2"",""OrderStatus"": ""Unshipped""}]}" ' Batch 2 File Dim a2 As String 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"}]} Dim success As Long success = 1 Dim json1 As New ChilkatJsonObject success = json1.Load(a1) Dim json2 As New ChilkatJsonObject success = json2.Load(a2) ' We're going to add the order records from json2 to json1. Dim jarr1 As ChilkatJsonArray Set jarr1 = json1.ArrayOf("payload.Orders") Dim jarr2 As ChilkatJsonArray Set jarr2 = json2.ArrayOf("payload.Orders") Dim i As Long i = 0 Dim numOrders As Long numOrders = jarr2.Size Do While (i < numOrders) Dim jOrder As ChilkatJsonObject Set jOrder = jarr2.ObjectAt(i) ' Assuming non-null return... success = jarr1.AddObjectCopyAt(-1,jOrder) i = i + 1 Loop ' Show the merged JSON. json1.EmitCompact = 0 Debug.Print json1.Emit() ' Result: ' { ' "payload": { ' "Orders": [ ' { ' "AmazonOrderId": "1", ' "OrderStatus": "Unshipped" ' }, ' { ' "AmazonOrderId": "2", ' "OrderStatus": "Unshipped" ' }, ' { ' "AmazonOrderId": "3", ' "OrderStatus": "Unshipped" ' }, ' { ' "AmazonOrderId": "4", ' "OrderStatus": "Unshipped" ' } ' ] ' } ' } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.