Member 14911997 Ответов: 1

Как загрузить JSON-файл с помощью компонента script в качестве исходной задачи в SSIS?


Я пытаюсь загрузить файл json в SSIS с помощью компонента script, но получаю следующую ошибку:-
Цитата:
в System.Web.Script.Сериализация.Класс javascriptserializer.Десериализация(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
в System.Web.Script.Сериализация.Класс javascriptserializer.Десериализация[T](строковый ввод)
в обсуждаемые.Метод createnewoutputrows()
в UserComponent.PrimeOutput(Int32 Outputs, Int32[] OutputIDs, PipelineBuffer[] Buffers, OutputNameMap OutputMap)
в корпорации Microsoft.От SQLServer.ДЦ.Производство.ScriptComponentHost.Метод primeoutput(int32 и выходы, типа int32[] outputIDs, буфер pipelinebuffer[] буферы)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoreSales
{
    class jrpproject
    {
        public string SalesID { get; set; }
        public string OrderID { get; set; }
        public string CustomerID { get; set; }
        public string CustomerName { get; set; }
        public string PostalCode { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Region { get; set; }
        public string Latitude { get; set; }
        public string Longitude { get; set; }
        public string Country { get; set; }
        public string ProductCategory { get; set; }
        public string ProductSubCategory { get; set; }
        public string CustomerSegment { get; set; }
        public string ProductContainer { get; set; }
        public string ProductName { get; set; }
        public string ProductBaseMargin { get; set; }
        public string OrderPriority { get; set; }
    
        public string OrderDate { get; set; }
        public string ShipDate { get; set; }
        public string ShipMode { get; set; }
        public string ShippingCost { get; set; }
        public string QuantityOrdered { get; set; }
        public string UnitPrice { get; set; }
    
        public string Sales { get; set; }
        public string Discount { get; set; }
        public string Profit { get; set; }
    
    }
}
#region Help: Introduction to the Script Component
/* The Script Component allows you to perform virtually any operation that can be accomplished in
* a .Net application within the context of an Integration Services data flow.
*
* Expand the other regions which have "Help" prefixes for examples of specific ways to use
* Integration Services features within this script component. */
#endregion

#region Namespaces

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using StoreSales;
using System.Collections.Generic;
using System.Text;
using System.Web.Script.Serialization;
using System.IO;
using System.Web.UI;
#endregion

///

/// This is the class to which to add your code. Do not change the name, attributes, or parent
/// of this class.
///
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    private string jsonfilecontent;
    private object row;
    #region Help: Using Integration Services variables and parameters
    /* To use a variable in this script, first ensure that the variable has been added to
    * either the list contained in the ReadOnlyVariables property or the list contained in
    * the ReadWriteVariables property of this script component, according to whether or not your
    * code needs to write into the variable. To do so, save this script, close this instance of
    * Visual Studio, and update the ReadOnlyVariables and ReadWriteVariables properties in the
    * Script Transformation Editor window.
    * To use a parameter in this script, follow the same steps. Parameters are always read-only.
    *
    * Example of reading from a variable or parameter:
    * DateTime startTime = Variables.MyStartTime;
    *
    * Example of writing to a variable:
    * Variables.myStringVariable = "new value";
    */
    #endregion
    #region Help:  Using Integration Services Connnection Managers
    /* Some types of connection managers can be used in this script component.  See the help topic
     * "Working with Connection Managers Programatically" for details.
     *
     * To use a connection manager in this script, first ensure that the connection manager has
     * been added to either the list of connection managers on the Connection Managers page of the
     * script component editor.  To add the connection manager, save this script, close this instance of
     * Visual Studio, and add the Connection Manager to the list.
     *
     * If the component needs to hold a connection open while processing rows, override the
     * AcquireConnections and ReleaseConnections methods.
     * 
     * Example of using an ADO.Net connection manager to acquire a SqlConnection:
     *  object rawConnection = Connections.SalesDB.AcquireConnection(transaction);
     *  SqlConnection salesDBConn = (SqlConnection)rawConnection;
     *
     * Example of using a File connection manager to acquire a file path:
     *  object rawConnection = Connections.Prices_zip.AcquireConnection(transaction);
     *  string filePath = (string)rawConnection;
     *
     * Example of releasing a connection manager:
     *  Connections.SalesDB.ReleaseConnection(rawConnection);
     */
    #endregion
    
    #region Help:  Firing Integration Services Events
    /* This script component can fire events.
     *
     * Example of firing an error event:
     *  ComponentMetaData.FireError(10, "Process Values", "Bad value", "", 0, out cancel);
     *
     * Example of firing an information event:
     *  ComponentMetaData.FireInformation(10, "Process Values", "Processing has started", "", 0, fireAgain);
     *
     * Example of firing a warning event:
     *  ComponentMetaData.FireWarning(10, "Process Values", "No rows were received", "", 0);
     */
    #endregion
    
    /// <summary>
    /// This method is called once, before rows begin to be processed in the data flow.
    ///
    /// You can remove this method if you don't need to do anything here.
    /// </summary>
    public override void PreExecute()
    {
        base.PreExecute();
        /*
         * Add your code here
         */
    }
    
    /// <summary>
    /// This method is called after all the rows have passed through this component.
    ///
    /// You can delete this method if you don't need to do anything here.
    /// </summary>
    public override void PostExecute()
    {
        base.PostExecute();
        /*
         * Add your code here
         */
    }
    
    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(@"D:\Data Analytics Class\Json FIle\200000.json");
    
        JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
    
        List<jrpproject> salesrows = js.Deserialize<list<jrpproject>>(jsonfilecontent);
        foreach (jrpproject row in salesrows)
        {
            Output0Buffer.AddRow();
            Output0Buffer.SalesID = row.SalesID;
            Output0Buffer.OrderID = row.OrderID;
            Output0Buffer.CustomerID = row.CustomerID;
            Output0Buffer.CustomerName = row.CustomerName;
            Output0Buffer.PostalCode = row.PostalCode;
            Output0Buffer.City = row.City;
            Output0Buffer.State = row.State;
            Output0Buffer.Region = row.Region;
            Output0Buffer.Latitude = row.Latitude;
            Output0Buffer.Longitude = row.Longitude;
            Output0Buffer.Country = row.Country;
            Output0Buffer.ProductCategory = row.ProductCategory;
            Output0Buffer.ProductSubCategory = row.ProductSubCategory;
            Output0Buffer.CustomerSegment = row.CustomerSegment;
            Output0Buffer.ProductContainer = row.ProductContainer;
            Output0Buffer.ProductName = row.ProductName;
            Output0Buffer.ProductBaseMargin = row.ProductBaseMargin;
            Output0Buffer.OrderPriority = row.OrderPriority;
            Output0Buffer.OrderDate = row.OrderDate;
            Output0Buffer.ShipDate = row.ShipDate;
            Output0Buffer.ShipMode = row.ShipMode;
            Output0Buffer.ShippingCost = row.ShippingCost;
            Output0Buffer.QuantityOrdered = row.QuantityOrdered;
            Output0Buffer.UnitPrice = row.UnitPrice;
            Output0Buffer.Sales = row.Sales;
            Output0Buffer.Discount = row.Discount;
            Output0Buffer.Profit = row.Profit;
        }
    }
}

Любое решение, Пожалуйста.....

Что я уже пробовал:

Я уже пробовал
1.другой код, чем показано выше
2.Добавьте больше ссылок
3.следуйте инструкциям Google
4.Найдите null в исходном файле

Richard MacCutchan

В вашем сообщении об ошибке отсутствует ключевая часть информации: бит, который говорит вам, в чем заключается ошибка.

1 Ответов

Рейтинг:
2

Sandeep Mewara

Возможно, это поможет вам достичь того, к чему вы стремитесь: Импорт файлов JSON с помощью служб SQL Server Integration Services[^]

Это подробное описание действий и состояний:

Цитата:
Службы SQL Server Integration Services изначально не поддерживают JSON, поэтому нам необходимо разработать пользовательский источник для задачи потока данных для загрузки файла JSON. В этом совете я расскажу о методе разработки индивидуального источника для загрузки файлов JSON с помощью .Сетевая библиотека.


Надеюсь, это поможет.