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
(PureBasic) Merge SP-API JSON Order ArraysSee more Amazon SP-API ExamplesDemonstrates how to merge JSON arrays for the case of Amazon SP-API orders.
IncludeFile "CkJsonArray.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; Batch 1 File a1.s = "{" + Chr(34) + "payload" + Chr(34) + ": {" + Chr(34) + "Orders" + Chr(34) + ": [{" + Chr(34) + "AmazonOrderId" + Chr(34) + ": " + Chr(34) + "1" + Chr(34) + "," + Chr(34) + "OrderStatus" + Chr(34) + ": " + Chr(34) + "Unshipped" + Chr(34) + "},{" + Chr(34) + "AmazonOrderId" + Chr(34) + ": " + Chr(34) + "2" + Chr(34) + "," + Chr(34) + "OrderStatus" + Chr(34) + ": " + Chr(34) + "Unshipped" + Chr(34) + "}]}" ; Batch 2 File a2.s = "{" + Chr(34) + "payload" + Chr(34) + ": {" + Chr(34) + "Orders" + Chr(34) + ": [{" + Chr(34) + "AmazonOrderId" + Chr(34) + ": " + Chr(34) + "3" + Chr(34) + "," + Chr(34) + "OrderStatus" + Chr(34) + ": " + Chr(34) + "Unshipped" + Chr(34) + "},{" + Chr(34) + "AmazonOrderId" + Chr(34) + ": " + Chr(34) + "4" + Chr(34) + "," + Chr(34) + "OrderStatus" + Chr(34) + ": " + Chr(34) + "Unshipped" + Chr(34) + "}]}" ; Required Merged File ; {"payload": {"Orders": [{"AmazonOrderId": "1","OrderStatus": "Unshipped"},{"AmazonOrderId": "2","OrderStatus": "Unshipped"},{"AmazonOrderId": "3","OrderStatus": "Unshipped"},{"AmazonOrderId": "4","OrderStatus": "Unshipped"}]} success.i = 1 json1.i = CkJsonObject::ckCreate() If json1.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json1,a1) json2.i = CkJsonObject::ckCreate() If json2.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json2,a2) ; We're going to add the order records from json2 to json1. jarr1.i = CkJsonObject::ckArrayOf(json1,"payload.Orders") jarr2.i = CkJsonObject::ckArrayOf(json2,"payload.Orders") i.i = 0 numOrders.i = CkJsonArray::ckSize(jarr2) While (i < numOrders) jOrder.i = CkJsonArray::ckObjectAt(jarr2,i) ; Assuming non-null return... CkJsonArray::ckAddObjectCopyAt(jarr1,-1,jOrder) i = i + 1 Wend ; Show the merged JSON. CkJsonObject::setCkEmitCompact(json1, 0) Debug CkJsonObject::ckEmit(json1) ; Result: ; { ; "payload": { ; "Orders": [ ; { ; "AmazonOrderId": "1", ; "OrderStatus": "Unshipped" ; }, ; { ; "AmazonOrderId": "2", ; "OrderStatus": "Unshipped" ; }, ; { ; "AmazonOrderId": "3", ; "OrderStatus": "Unshipped" ; }, ; { ; "AmazonOrderId": "4", ; "OrderStatus": "Unshipped" ; } ; ] ; } ; } CkJsonObject::ckDispose(json1) CkJsonObject::ckDispose(json2) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.