(SQL Server) Create JSON Array of Strings
Demonstrates how to create a JSON array of strings.
-- 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)
-- The goal of this example is to produce this:
-- [
-- "tag1",
-- "tag2",
-- "tag3"
-- ]
DECLARE @jarr int
-- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jarr OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @jarr, 'AddStringAt', @success OUT, -1, 'tag1'
EXEC sp_OAMethod @jarr, 'AddStringAt', @success OUT, -1, 'tag2'
EXEC sp_OAMethod @jarr, 'AddStringAt', @success OUT, -1, 'tag3'
EXEC sp_OASetProperty @jarr, 'EmitCompact', 0
EXEC sp_OAMethod @jarr, 'Emit', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jarr
END
GO
|