簡體   English   中英

在SQL Server 2016中打開JSON

[英]Open JSON in SQL Server 2016

我正在使用具有Open JSON功能的SQL Server 2016,該功能用於將JSON文件導入數據庫表中。

我有以下格式的Json,標題和值與標題下的行相同,如excel。

我必須創建一個Cell_State表,標題值作為列, 作為行。

請指教。

DECLARE @json NVARCHAR(MAX) = N'{
   "CELL_STATE" : {

      "header" : [
         "Node",
         "Logtime",
         "Cell",
         "Cell state",
         "SectorCarrier state",
         "SectorEquipmentFunction"
      ],

            "value" : [
               "LBI874",
               "2016-06-02 07:05",
               "L38741",
               "UNLOCKED, DISABLED",
               "SectorCarrier=1 DISABLED",
               "SectorEquipmentFunction=1 fqband=7"
            ]

              "value" : [
               "LBI874",
               "2016-06-02 07:05",
               "L38742",
               "UNLOCKED, DISABLED",
               "SectorCarrier=2 DISABLED",
               "SectorEquipmentFunction=2 fqband=7"
            ]
         } 

         }'

SELECT * FROM OPENJSON(@json, '$')

您的JSON無效,在第一個值塊后缺少逗號:

DECLARE @json NVARCHAR(MAX) = N'{
   "CELL_STATE" : {

      "header" : [
         "Node",
         "Logtime",
         "Cell",
         "Cell state",
         "SectorCarrier state",
         "SectorEquipmentFunction"
      ],

            "value" : [
               "LBI874",
               "2016-06-02 07:05",
               "L38741",
               "UNLOCKED, DISABLED",
               "SectorCarrier=1 DISABLED",
               "SectorEquipmentFunction=1 fqband=7"
            ],

              "value" : [
               "LBI874",
               "2016-06-02 07:05",
               "L38742",
               "UNLOCKED, DISABLED",
               "SectorCarrier=2 DISABLED",
               "SectorEquipmentFunction=2 fqband=7"
            ]
         } 

         }'

您的JSON無效。 您錯過了第一個值塊后的逗號。 正確的JSON如下所示:

{
    "CELL_STATE": {

        "header": [
            "Node",
            "Logtime",
            "Cell",
            "Cell state",
            "SectorCarrier state",
            "SectorEquipmentFunction"
        ],

        "value": [
            "LBI874",
            "2016-06-02 07:05",
            "L38741",
            "UNLOCKED, DISABLED",
            "SectorCarrier=1 DISABLED",
            "SectorEquipmentFunction=1 fqband=7"
        ],

        "value": [
            "LBI874",
            "2016-06-02 07:05",
            "L38742",
            "UNLOCKED, DISABLED",
            "SectorCarrier=2 DISABLED",
            "SectorEquipmentFunction=2 fqband=7"
        ]
    }

}

這樣可以解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM