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
(SQL Server) JSON Copy ObjectsCopy objects from one JSON document to another.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @json1 int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json1 OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @json1, 'UpdateString', @success OUT, 'ID1.cn', 'Name' EXEC sp_OAMethod @json1, 'UpdateString', @success OUT, 'ID1.objectGUID', 'GUID' EXEC sp_OAMethod @json1, 'UpdateString', @success OUT, 'ID2.cn', 'Name' EXEC sp_OAMethod @json1, 'UpdateString', @success OUT, 'ID2.objectGUID', 'GUID' EXEC sp_OASetProperty @json1, 'EmitCompact', 0 EXEC sp_OAMethod @json1, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- json1 contains: -- { -- "ID1": { -- "cn": "Name", -- "objectGUID": "GUID" -- }, -- "ID2": { -- "cn": "Name", -- "objectGUID": "GUID" -- } -- } DECLARE @json2 int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json2 OUT EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'Name1.ID1.cn', 'Name' EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'Name1.ID1.objectGUID', 'GUID' EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'Name1.ID2.cn', 'Name' EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'Name1.ID2.objectGUID', 'GUID' EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'Name2.ID3.cn', 'Name' EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'Name2.ID3.objectGUID', 'GUID' EXEC sp_OASetProperty @json2, 'EmitCompact', 0 EXEC sp_OAMethod @json2, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- { -- "Name1": { -- "ID1": { -- "cn": "Name", -- "objectGUID": "GUID" -- }, -- "ID2": { -- "cn": "Name", -- "objectGUID": "GUID" -- } -- }, -- "Name2": { -- "ID3": { -- "cn": "Name", -- "objectGUID": "GUID" -- } -- } -- } -- Copy Name1, Name2 into json1 DECLARE @i int SELECT @i = 0 DECLARE @numMembers int EXEC sp_OAGetProperty @json2, 'Size', @numMembers OUT WHILE @i < @numMembers BEGIN DECLARE @jsonObj int EXEC sp_OAMethod @json2, 'ObjectAt', @jsonObj OUT, @i EXEC sp_OAMethod @json2, 'NameAt', @sTmp0 OUT, @i EXEC sp_OAMethod @json1, 'AppendObjectCopy', @success OUT, @sTmp0, @jsonObj SELECT @i = @i + 1 END -- Now see what json1 contains: EXEC sp_OAMethod @json1, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- { -- "ID1": { -- "cn": "Name", -- "objectGUID": "GUID" -- }, -- "ID2": { -- "cn": "Name", -- "objectGUID": "GUID" -- }, -- "Name1": { -- "ID1": { -- "cn": "Name", -- "objectGUID": "GUID" -- }, -- "ID2": { -- "cn": "Name", -- "objectGUID": "GUID" -- } -- }, -- "Name2": { -- "ID3": { -- "cn": "Name", -- "objectGUID": "GUID" -- } -- } -- } EXEC @hr = sp_OADestroy @json1 EXEC @hr = sp_OADestroy @json2 END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.