Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
在查询中指定 FOR JSON RAW 时,将以展平的 JSON 表示形式返回每一行。
FOR JSON RAW
建议在以 JSON 对象形式检索查询结果时使用此子句方法,因为它最易于分析和理解。
以下查询使用 FOR JSON RAW 返回 Employees 表中的雇员信息:
SELECT emp.EmployeeID, so.CustomerID, so.Region FROM Employees AS emp KEY JOIN SalesOrders AS so WHERE emp.EmployeeID <= 195 ORDER BY 1 FOR JSON RAW;
使用 FOR JSON AUTO 时会返回分级嵌套的结果,与 其不同的是,使用 FOR JSON RAW 会返回展平的结果集:
[ { "EmployeeID" : 129, "CustomerID" : 107, "Region" : "Eastern" }, { "EmployeeID" : 129, "CustomerID" : 119, "Region" : "Western" }, ... { "EmployeeID" : 129, "CustomerID" : 131, "Region" : "Eastern" }, { "EmployeeID" " 195, "CustomerID" : 176, "Region" : "Eastern" } ]