我有以下JSON字符串,我正在尝试检索两个值
declare @outcomes nvarchar(max)
set @outcomes = '{"Outcomes": [{"rule": "FC001", "outcome": "False", "test":
"abc"}]}'
select outcome,[rule] from OPENJSON(@outcomes)
WITH
(outcome nvarchar(max) '$.Outcomes.outcome.value',
[rule] nvarchar(max) '$.Outcomes.rule')
我想找回“规则”和“结果”。
如果删除数组,我可以得到它们,但是没问题,但是它们在数组中的事实使我得到了NULL值。
如何查询JSON以获取嵌套数组中的值?这是一个更大的JSON字符串的简短示例。
我尝试使用CROSS APPLY,因为我看到其他人说它可以工作,但到目前为止我还没有成功。添加AS JSON
也没有任何区别。
select outcome,[rule] from OPENJSON(@outcomes)
WITH
(outcome nvarchar(max) '$.Outcomes.outcome',
[rule] nvarchar(max) '$.Outcomes.rule') as a
cross apply openjson
(a.outcome nvarchar(max) '$.Outcomes.outcome',
a.[rule] nvarchar(max) '$.Outcomes.rule')