--适合于 SQL Server2016+
USE [tempdb]
GO
CREATE OR ALTER PROC [dbo].[Proc_Test]
@json NVARCHAR(MAX) = '[{"GoodsId": 3, "Quantity": 10}, {"GoodsId": 8,"Quantity": 20}]'
AS
BEGIN
SET NOCOUNT ON;
SELECT goodsId,quantity
FROM OPENJSON(@json)
WITH (
goodsId INT 'strict $.GoodsId',
quantity INT 'strict $.Quantity'
)
END
GO
EXEC [dbo].[Proc_Test]
/*
goodsId quantity
3 10
8 20
*/
将表的记录转为json:
SELECT TOP 2 * FROM MASTER.dbo.spt_values FOR JSON PATH
/*
[{"name":"rpc","number":1,"type":"A ","status":0},{"name":"pub","number":2,"type":"A ","status":0}]
*/