首页 > 解决方案 > 使用 SSIS 将 JSON 文件导入 SQL Server

问题描述

JSON 文件有 2 个部分(嵌套),我可以导入第一个我不知道为什么的部分,对此有什么想法吗?第二部分的第一列NULL在数据库中显示了我

这是 JSON 文件格式:

这是 JSON 文件格式

我的代码是

    public override void CreateNewOutputRows()
{
    /*
    Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
    For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
    */
    String jsonFileContent = File.ReadAllText(@"C:\Json XLM project SSIS\FileSample.JSON");
    JavaScriptSerializer js = new JavaScriptSerializer();
    List<Order> orders = js.Deserialize<List<Order>>(jsonFileContent);
    foreach (Order order in orders)
    {
        Output0Buffer.AddRow();
        Output0Buffer.TrackingNumber = order.TrackingNumber;
        Output0Buffer.LocalReferenceNumber = order.LocalReferenceNumber;
        Output0Buffer.TotalShipmentPieces = order.TotalShipmentPieces;
        Output0Buffer.TotalShipmentValue = order.TotalShipmentValue;
        Output0Buffer.ShipmentCurrency = order.ShipmentCurrency;
        Output0Buffer.ShipmentGrossWeight = order.ShipmentGrossWeight;
        Output0Buffer.ShipmentNetWeight = order.ShipmentNetWeight;
        Output0Buffer.BorderTransportMode = order.BorderTransportMode;
        Output0Buffer.ConveyanceDetail = order.ConveyanceDetail;
        Output0Buffer.TransportId = order.TransportId;
        Output0Buffer.Region = order.Region;
        Output0Buffer.WarehouseLocation = order.WarehouseLocation;
        Output0Buffer.InvoiceNumber = order.InvoiceNumber;
        Output0Buffer.InvoiceDate = order.InvoiceDate;
        Output0Buffer.ItemCategoryId = order.ItemCategoryId;
        Output0Buffer.InsuredValue = order.InsuredValue;
        Output0Buffer.SoldByShipmentPartyAddressId =     order.SoldByShipmentPartyAddressId; 

    }
}

提前致谢。

标签: jsonssissql-server-2008-r2etlscript-component

解决方案


推荐阅读