我正在使用SQL SERVER 2016 JSON结果,但我不知道为什么它会将所有内容转换为数组,例如如果我执行以下查询,它将返回一个数组而不是一个对象:
SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH
结果是:
[{"One":1,"Two":2,"Three":3}]
但我希望它能回归:
{"One":1,"Two":2,"Three":3}
我也测试了这个查询,但结果是一样的,同样是一个数组:
SELECT TOP 1 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH
答案 0 :(得分:9)
您只需要WITHOUT_ARRAY_WRAPPER
选项:
SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH ,WITHOUT_ARRAY_WRAPPER;