为什么 SQL returns 是数组而不是对象?

Why SQL returns an Array instead of an Object?

我正在使用 SQL SERVER 2016 JSON 结果,但我不知道为什么它将所有内容都转换为数组,例如如果我执行以下查询,它 return 是一个数组而不是对象:

SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH

结果是:

[{"One":1,"Two":2,"Three":3}]

但我想 return:

{"One":1,"Two":2,"Three":3}

我也测试了这个查询,但结果是一样的,还是一个数组:

SELECT TOP 1 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH

您只需要 WITHOUT_ARRAY_WRAPPER 选项:

SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH ,WITHOUT_ARRAY_WRAPPER;