嘗試將 DataFactory 的元資料輸出寫入 SQL Server 資料庫時出現此錯誤。
“errorCode”:“2402”,
“message”:“對 SQL Server 執行失敗
。SQL 錯誤號:13609。
錯誤訊息:JSON 文本格式不正確。在位置 0 處發現了意外的字符 'S'。”
我在 SQL Server 資料庫中使用存盤程序。
元資料輸出:
{
"childItems": [
{
"name": "DemoFile1",
"type": "File"
},
{
"name": "DemoFile2",
"type": "File"
} ]
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime",
"executionDuration": 0
}
程式代碼:
CREATE PROCEDURE prod1
@parameter1 NVARCHAR(max)
AS
BEGIN
INSERT INTO [dbo].[Table1] ([name], [type])
SELECT
name, type
FROM
OPENJSON(@parameter1)
WITH (
name NVARCHAR(max) '$.name',
type NVARCHAR(max) '$.type'
) AS jsonValues
END
蒂亞!
uj5u.com熱心網友回復:
請嘗試以下解決方案。
少了幾件事:
- 花括號 { 和 }。
- 一個逗號
], OPENJSON(@parameter1, '$.childItems')第二個引數。
您始終可以通過 T-SQLISJSON()函式檢查它是否是格式正確的 JSON 。
查詢陳述句
DECLARE @parameter1 NVARCHAR(max) =
N'{
"childItems": [
{
"name": "DemoFile1",
"type": "File"
},
{
"name": "DemoFile2",
"type": "File"
}
],
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime",
"executionDuration": 0
}';
IF ISJSON(@parameter1) = 1
SELECT name, type
FROM OPENJSON(@parameter1, '$.childItems')
WITH (
name NVARCHAR(max) '$.name',
type NVARCHAR(max) '$.type'
) AS jsonValues
ELSE
THROW 50000,'JSON is not well-formed',1;
輸出
----------- ------
| name | type |
----------- ------
| DemoFile1 | File |
| DemoFile2 | File |
----------- ------
uj5u.com熱心網友回復:
您的 json 結構是錯誤的,并且是您的錯誤原因。實際上你錯過了{,}你的 json 應該如下所示:
{"childItems": [ { "name": "DemoFile1", "type": "File" }, { "name": "DemoFile2", "type": "File" } ]}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/404976.html
標籤:
上一篇:SQL查詢在一張表中聚合月份
下一篇:在SQL中動態選擇列
