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) Load a JSON ArrayThe Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.
// Important: See this note about string length limitations for strings returned by sp_OAMethod calls. // CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int DECLARE @sTmp0 nvarchar(4000) DECLARE @success int -- Imagine we want to load this JSON array for parsing: DECLARE @jsonArrayStr nvarchar(4000) SELECT @jsonArrayStr = '[{"id":200},{"id":196}]' -- First wrap it in a JSON object by prepending "{ "array":" and appending "}" DECLARE @sbJson int EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbJson OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @sbJson, 'Append', @success OUT, '{"array":' EXEC sp_OAMethod @sbJson, 'Append', @success OUT, @jsonArrayStr EXEC sp_OAMethod @sbJson, 'Append', @success OUT, '}' DECLARE @json int EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT EXEC sp_OAMethod @sbJson, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0 -- Now we can get the JSON array DECLARE @jArray int EXEC sp_OAMethod @json, 'ArrayAt', @jArray OUT, 0 -- Do what you want with the JSON array... -- For example: DECLARE @jObjId int EXEC sp_OAMethod @jArray, 'ObjectAt', @jObjId OUT, 0 EXEC sp_OAMethod @jObjId, 'IntOf', @iTmp0 OUT, 'id' PRINT @iTmp0 EXEC @hr = sp_OADestroy @jObjId EXEC @hr = sp_OADestroy @jArray EXEC @hr = sp_OADestroy @sbJson EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.