![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Using JSON StringOf with Non-String MembersSee more JSON ExamplesIf a JSON member is a boolean, integer, or null, usingStringOf will return its string representation.
-- 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) -- Create JSON with members of different data types. DECLARE @json int EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'a', 123 EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'b', 1 EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'c' EXEC sp_OASetProperty @json, 'EmitCompact', 0 EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- Resulting JSON: -- { -- "a": 123, -- "b": true, -- "c": null -- } DECLARE @a nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @a OUT, 'a' PRINT @a DECLARE @b nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @b OUT, 'b' PRINT @b DECLARE @c nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @c OUT, 'c' PRINT @c -- Output -- 123 -- true -- null -- If you want to get the integer, boolean, or null value -- you need to use the methods matching the data type DECLARE @ival int EXEC sp_OAMethod @json, 'IntOf', @ival OUT, 'a' DECLARE @bval int EXEC sp_OAMethod @json, 'BoolOf', @bval OUT, 'b' DECLARE @hasNull int EXEC sp_OAMethod @json, 'IsNullOf', @hasNull OUT, 'c' EXEC @hr = sp_OADestroy @json END GO |
||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.