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
(Swift 3,4,5...) Merge SP-API JSON Order ArraysSee more Amazon SP-API ExamplesDemonstrates how to merge JSON arrays for the case of Amazon SP-API orders.
func chilkatTest() { // Batch 1 File var a1: String? = "{\"payload\": {\"Orders\": [{\"AmazonOrderId\": \"1\",\"OrderStatus\": \"Unshipped\"},{\"AmazonOrderId\": \"2\",\"OrderStatus\": \"Unshipped\"}]}" // Batch 2 File var a2: String? = "{\"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"}]} var success: Bool = true let json1 = CkoJsonObject()! json1.load(a1) let json2 = CkoJsonObject()! json2.load(a2) // We're going to add the order records from json2 to json1. var jarr1: CkoJsonArray? = json1.array(of: "payload.Orders") var jarr2: CkoJsonArray? = json2.array(of: "payload.Orders") var i: Int = 0 var numOrders: Int = jarr2!.size.intValue while (i < numOrders) { var jOrder: CkoJsonObject? = jarr2!.object(at: i) // Assuming non-null return... jarr1!.addObjectCopy(at: -1, jsonObj: jOrder) i = i + 1 } // Show the merged JSON. json1.emitCompact = false 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.