简体   繁体   English

使用vb.net将JSON文件导入SQL Server数据库

[英]Importing a JSON file to a SQL Server database using vb.net

I want to import a big JSON file with this structure: 我要导入具有此结构的大JSON文件:

{
  "series_id":"NG.RL2R04SOK_1.A",
  "name":"Oklahoma Natural Gas Plant Liquids, Reserves Revision Decreases, Annual",
  "units":"Million Barrels",
  "f":"A",
  "unitsshort":"MMbbl",
  "description":"Oklahoma Natural Gas Plant Liquids, Reserves Revision Decreases",
  "copyright":"None","source":"EIA, U.S. Energy Information Administration",
  "iso3166":"USA-OK",
  "start":"1979",
  "end":"2008",
  "last_updated":"13-AUG-13 11.49.51 AM",
  "data":[
     ["2008","136"],
     ["2007","73"],
     ... 
     ["1980","69"],
     ["1979","54"]
  ]
}

into a SQL Server database. 到SQL Server数据库中。

Usually I use VB.net to import CSV/TXT/Excel into this database, but I have no knowledge of JSON. 通常,我使用VB.net将CSV / TXT / Excel导入此数据库,但是我不了解JSON。

Is there a simple way to do that ? 有没有简单的方法可以做到这一点?

Thanks a lot 非常感谢

In SQL Server 2016 you can open (and import) json files directly using TSQL: 在SQL Server 2016中,您可以直接使用TSQL打开(并导入)json文件:

SELECT import.*
FROM OPENROWSET (BULK 'f:\import.json', SINGLE_CLOB) as j
CROSS APPLY OPENJSON(BulkColumn)
WITH( 
    [series_id]    nvarchar(100), 
    [name]         nvarchar(100),
    [units]        nvarchar(100),
    [f]            nvarchar(100),
    [unitsshort]   nvarchar(100),
    [description]  nvarchar(100),
    [copyright]    nvarchar(100),
    [iso3166]      nvarchar(100),
    [start]        int,
    [end]          int,
    [last_updated] nvarchar(100),
    [data]         nvarchar(100) 
) AS import

This query returns a table containing data read from json file and organized with the columns specified in the WITH clause. 该查询返回一个表,该表包含从json文件读取的数据,并按WITH子句中指定的列进行组织。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM