Why SQL returns an Array instead of an Object?

青春壹個敷衍的年華 提交于 2020-01-14 08:46:07

问题


I'm using SQL SERVER 2016 JSON result, but I don't know why it converts everything to array, e.g. if I execute the following query it returns an array instead of an object:

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

The result is:

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

But I would like it to return:

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

Also I tested this query, but the result was the same, again an array:

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

回答1:


You just need the WITHOUT_ARRAY_WRAPPER option:

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


来源:https://stackoverflow.com/questions/39849997/why-sql-returns-an-array-instead-of-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!