2017-11-09 16 views
0

私はそれを実行するたびにJSONファイルを更新するパッケージを作成しました。次の段階では、1行のデータを表にロードします。SSISスクリプトコンポーネントJSONからSQL Serverテーブル

私はそれを読み込むためにスクリプトタスクを使用しています。スクリプトコンポーネントは、列ヘッダーと列の値として異なるキーと値のペアを識別するために必要 https://query2.finance.yahoo.com/v7/finance/quote?symbols=AAPL

:後

は私のJSONファイルです。それに応じて出力設定済み

:ここ

SSIS output config

は、ビルドアクションにエラーを与えていない私のスクリプトタスクC#のスクリプトです:私は、ビルド上の任意のエラーを得ることはありません

#region Namespaces 
using System; 
using System.Data; 
using Microsoft.SqlServer.Dts.Runtime; 
using Microsoft.SqlServer.Dts.Pipeline.Wrapper; 
using Microsoft.SqlServer.Dts.Runtime.Wrapper; 
using System.Web.Script.Serialization; 
using Microsoft.SqlServer.Dts.Pipeline; 
#endregion 

namespace SC_ce793b89c26a4be48b4f5354892c6d24 
{ 
    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] 
    public class ScriptMain : UserComponent 
    { 
     public override void PreExecute() 
     { 
      base.PreExecute(); 
     } 

     public override void PostExecute() 
     { 
      base.PostExecute(); 
     } 

     class result 
     { 
      public string language { get; set;} 
      public string quoteType { get; set; } 
      public string quoteSourceName { get; set; } 
      public string currency { get; set; } 
      public decimal sharesOutstanding { get; set; } 
      public decimal bookValue { get; set; } 
      public decimal fiftyDayAverage { get; set; } 
      public decimal epsTrailingTwelveMonths { get; set; } 
      public decimal forwardPE { get; set; } 
      public decimal priceToBook { get; set; } 
      public decimal trailingAnnualDividendYield { get; set; } 
      public string tradeable { get; set; } 
      public decimal fiftyDayAverageChange { get; set; } 
      public decimal fiftyDayAverageChangePercent { get; set; } 
      public decimal twoHundredDayAverage { get; set; } 
      public decimal twoHundredDayAverageChange { get; set; } 
      public decimal priceHint { get; set; } 
      public decimal fiftyTwoWeekLowChange { get; set; } 
      public string fullExchangeName { get; set; } 
      public string longName { get; set; } 
      public string financialCurrency { get; set; } 
      public decimal averageDailyVolume3Month { get; set; } 
      public decimal averageDailyVolume10Day { get; set; } 
      public decimal fiftyTwoWeekLow { get; set; } 
      public decimal fiftyTwoWeekHigh { get; set; } 
      public decimal dividendDate { get; set; } 
      public string shortName { get; set; } 
      public string marketState { get; set; } 
      public decimal regularMarketChangePercent { get; set; } 
      public decimal regularMarketPreviousClose { get; set; } 
      public decimal bid { get; set; } 
      public decimal ask { get; set; } 
      public decimal bidSize { get; set; } 
      public decimal askSize { get; set; } 
      public string messageBoardId { get; set; } 
      public decimal epsForward { get; set; } 
      public decimal twoHundredDayAverageChangePercent { get; set; } 
      public decimal marketCap { get; set; } 
      public decimal exchangeDataDelayedBy { get; set; } 
      public string exchange { get; set; } 
      public decimal regularMarketPrice { get; set; } 
      public decimal regularMarketTime { get; set; } 
      public decimal regularMarketChange { get; set; } 
      public decimal regularMarketOpen { get; set; } 
      public decimal regularMarketDayHigh { get; set; } 
      public decimal regularMarketDayLow { get; set; } 
      public decimal regularMarketVolume { get; set; } 
      public string market { get; set; } 
      public decimal sourceInterval { get; set; } 
      public string exchangeTimezoneName { get; set; } 
      public string exchangeTimezoneShortName { get; set; } 
      public decimal gmtOffSetMilliseconds { get; set; } 
      public decimal earningsTimestamp { get; set; } 
      public decimal earningsTimestampStart { get; set; } 
      public decimal earningsTimestampEnd { get; set; } 
      public decimal trailingAnnualDividendRate { get; set; } 
      public decimal trailingPE { get; set; } 
      public decimal fiftyTwoWeekLowChangePercent { get; set; } 
      public decimal fiftyTwoWeekHighChange { get; set; } 
      public decimal fiftyTwoWeekHighChangePercent { get; set; } 
      public string symbol { get; set; } 
     } 

     class quoteResponse 
     { 
      public result result { get; set; } 
     } 

     public override void Input0_ProcessInputRow(Input0Buffer Row) 
     { 
      JavaScriptSerializer js = new JavaScriptSerializer(); 

      BlobColumn combinedColumn = Row.Column0; 

      string reviewConverted = System.Text.Encoding.ASCII.GetString(combinedColumn.GetBlobData(0, Convert.ToInt32(combinedColumn.Length))); 

      quoteResponse quoteResponse = js.Deserialize<quoteResponse>(reviewConverted); 

      Row.regularMarketChangePercent = quoteResponse.result.regularMarketChangePercent; 
      Row.regularMarketChange = quoteResponse.result.regularMarketChange; 
      Row.regularMarketDayHigh = quoteResponse.result.regularMarketDayHigh; 
      Row.regularMarketDayLow = quoteResponse.result.regularMarketDayLow; 
      Row.epsTrailingTwelveMonths = quoteResponse.result.epsTrailingTwelveMonths; 
      Row.regularMarketPrice = quoteResponse.result.regularMarketPrice; 
      Row.marketCap = quoteResponse.result.marketCap; 
      Row.trailingPE = quoteResponse.result.trailingPE; 
      Row.symbol = quoteResponse.result.symbol; 
      Row.regularMarketVolume = quoteResponse.result.regularMarketVolume; 
      Row.fiftyTwoWeekHigh = quoteResponse.result.fiftyTwoWeekHigh; 
      Row.fiftyTwoWeekLow = quoteResponse.result.fiftyTwoWeekLow; 
      Row.xask = quoteResponse.result.ask; 
      Row.xaskSize = quoteResponse.result.askSize; 
      Row.xaverageDailyVolume10Day = quoteResponse.result.averageDailyVolume10Day; 
      Row.xaverageDailyVolume3Month = quoteResponse.result.averageDailyVolume3Month; 
      Row.xbid = quoteResponse.result.bid; 
      Row.xbidSize = quoteResponse.result.bidSize; 
      Row.xbookValue = quoteResponse.result.bookValue; 
      Row.xcurrency = quoteResponse.result.currency; 
      Row.xdividendDate = quoteResponse.result.dividendDate; 
      Row.xearningsTimestamp = quoteResponse.result.earningsTimestamp; 
      Row.xearningsTimestampEnd = quoteResponse.result.earningsTimestampEnd; 
      Row.xearningsTimestampStart = quoteResponse.result.earningsTimestampStart; 
      Row.xepsForward = quoteResponse.result.epsForward; 
      Row.xexchange = quoteResponse.result.exchange; 
      Row.xexchangeDataDelayedBy = quoteResponse.result.exchangeDataDelayedBy; 
      Row.xexchangeTimezoneName = quoteResponse.result.exchangeTimezoneName; 
      Row.xexchangeTimezoneShortName = quoteResponse.result.exchangeTimezoneShortName; 
      Row.xfiftyDayAverage = quoteResponse.result.fiftyDayAverage; 
      Row.xfiftyDayAverageChange = quoteResponse.result.fiftyDayAverageChange; 
      Row.xfiftyDayAverageChangePercent = quoteResponse.result.fiftyDayAverageChangePercent; 
      Row.xfiftyTwoWeekHighChange = quoteResponse.result.fiftyTwoWeekHighChange; 
      Row.xfiftyTwoWeekHighChangePercent = quoteResponse.result.fiftyTwoWeekHighChangePercent; 
      Row.xfiftyTwoWeekLowChange = quoteResponse.result.fiftyTwoWeekLowChange; 
      Row.xfiftyTwoWeekLowChangePercent = quoteResponse.result.fiftyTwoWeekLowChangePercent; 
      Row.xfinancialCurrency = quoteResponse.result.financialCurrency; 
      Row.xforwardPE = quoteResponse.result.forwardPE; 
      Row.xfullExchangeName = quoteResponse.result.fullExchangeName; 
      Row.xgmtOffSetMilliseconds = quoteResponse.result.gmtOffSetMilliseconds; 
      Row.xlanguage = quoteResponse.result.language; 
      Row.xlongName = quoteResponse.result.longName; 
      Row.xmarket = quoteResponse.result.market; 
      Row.xmarketState = quoteResponse.result.marketState; 
      Row.xmessageBoardId = quoteResponse.result.messageBoardId; 
      Row.xpriceHint = quoteResponse.result.priceHint; 
      Row.xpriceToBook = quoteResponse.result.priceToBook; 
      Row.xquoteSourceName = quoteResponse.result.quoteSourceName; 
      Row.xquoteType = quoteResponse.result.quoteType; 
      Row.xregularMarketOpen = quoteResponse.result.regularMarketOpen; 
      Row.xregularMarketPreviousClose = quoteResponse.result.regularMarketPreviousClose; 
      Row.xregularMarketTime = quoteResponse.result.regularMarketTime; 
      Row.xsharesOutstanding = quoteResponse.result.sharesOutstanding; 
      Row.xshortName = quoteResponse.result.shortName; 
      Row.xsourceInterval = quoteResponse.result.sourceInterval; 
      Row.xtradeable = quoteResponse.result.tradeable; 
      Row.xtrailingAnnualDividendRate = quoteResponse.result.trailingAnnualDividendRate; 
      Row.xtrailingAnnualDividendYield = quoteResponse.result.trailingAnnualDividendYield; 
      Row.xtwoHundredDayAverage = quoteResponse.result.twoHundredDayAverage; 
      Row.xtwoHundredDayAverageChange = quoteResponse.result.twoHundredDayAverageChange; 
      Row.xtwoHundredDayAverageChangePercent = quoteResponse.result.twoHundredDayAverageChangePercent; 

      Row.regularMarketChangePercent_IsNull = true; 
      Row.regularMarketChange_IsNull = true; 
      Row.regularMarketDayHigh_IsNull = true; 
      Row.regularMarketDayLow_IsNull = true; 
      Row.epsTrailingTwelveMonths_IsNull = true; 
      Row.regularMarketPrice_IsNull = true; 
      Row.marketCap_IsNull = true; 
      Row.trailingPE_IsNull = true; 
      Row.symbol_IsNull = true; 
      Row.regularMarketVolume_IsNull = true; 
      Row.fiftyTwoWeekHigh_IsNull = true; 
      Row.fiftyTwoWeekLow_IsNull = true; 
      Row.xask_IsNull = true; 
      Row.xaskSize_IsNull = true; 
      Row.xaverageDailyVolume10Day_IsNull = true; 
      Row.xaverageDailyVolume3Month_IsNull = true; 
      Row.xbid_IsNull = true; 
      Row.xbidSize_IsNull = true; 
      Row.xbookValue_IsNull = true; 
      Row.xcurrency_IsNull = true; 
      Row.xdividendDate_IsNull = true; 
      Row.xearningsTimestamp_IsNull = true; 
      Row.xearningsTimestampEnd_IsNull = true; 
      Row.xearningsTimestampStart_IsNull = true; 
      Row.xepsForward_IsNull = true; 
      Row.xexchange_IsNull = true; 
      Row.xexchangeDataDelayedBy_IsNull = true; 
      Row.xexchangeTimezoneName_IsNull = true; 
      Row.xexchangeTimezoneShortName_IsNull = true; 
      Row.xfiftyDayAverage_IsNull = true; 
      Row.xfiftyDayAverageChange_IsNull = true; 
      Row.xfiftyDayAverageChangePercent_IsNull = true; 
      Row.xfiftyTwoWeekHighChange_IsNull = true; 
      Row.xfiftyTwoWeekHighChangePercent_IsNull = true; 
      Row.xfiftyTwoWeekLowChange_IsNull = true; 
      Row.xfiftyTwoWeekLowChangePercent_IsNull = true; 
      Row.xfinancialCurrency_IsNull = true; 
      Row.xforwardPE_IsNull = true; 
      Row.xfullExchangeName_IsNull = true; 
      Row.xgmtOffSetMilliseconds_IsNull = true; 
      Row.xlanguage_IsNull = true; 
      Row.xlongName_IsNull = true; 
      Row.xmarket_IsNull = true; 
      Row.xmarketState_IsNull = true; 
      Row.xmessageBoardId_IsNull = true; 
      Row.xpriceHint_IsNull = true; 
      Row.xpriceToBook_IsNull = true; 
      Row.xquoteSourceName_IsNull = true; 
      Row.xquoteType_IsNull = true; 
      Row.xregularMarketOpen_IsNull = true; 
      Row.xregularMarketPreviousClose_IsNull = true; 
      Row.xregularMarketTime_IsNull = true; 
      Row.xsharesOutstanding_IsNull = true; 
      Row.xshortName_IsNull = true; 
      Row.xsourceInterval_IsNull = true; 
      Row.xtradeable_IsNull = true; 
      Row.xtrailingAnnualDividendRate_IsNull = true; 
      Row.xtrailingAnnualDividendYield_IsNull = true; 
      Row.xtwoHundredDayAverage_IsNull = true; 
      Row.xtwoHundredDayAverageChange_IsNull = true; 
      Row.xtwoHundredDayAverageChangePercent_IsNull = true; 
     } 
    } 
} 

が、私は実行で1つを得る:

でSC_ce793b89c26a4be48b4f5354892c6d24.Scr Microsoft.SqlServer.Dts.Pipeline.ScriptComponent.ProcessInput(のInt32 InputIDでUserComponent.ProcessInput(のInt32 InputID、文字列InputName、PipelineBufferバッファ、OutputNameMap OutputMap)でiptMain.Input0_ProcessInputRow UserComponent.Input0_ProcessInputで(Input0Buffer行) (Input0Buffer緩衝液) 、PipelineBufferバッファMicrosoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(のInt32 inputID、PipelineBufferバッファで) )

は、私の知る限り、私は間違って何もしておりません知っているように、ちょうどこの事を取得することはできません走るどんな助けもありがとうございます。

答えて

0

質問に表示される内容が、例外ではなくスタックトレースの一部であるように見えるため、実際にどのようなエラーが発生しているのかわかりません。

のオブジェクトがresultであるため、実際の問題はNullReferenceExecptionであることを喜んで賭けています。 resultがnullである理由は、逆シリアル化しようとしているクラス構造が、逆シリアル化しているJSONの構造と一致しないためです。特に

、私が見る二つの問題があります:JSONで

  1. は、result値は、(角括弧[]で囲まれた)配列ですが、あなたのquoteResponseクラスで、あなたはそれを定義しています単一のオブジェクトとして。
  2. JSONでは、quoteResponseは外側のオブジェクトの内側にあります。このオブジェクトのクラスがありません。

、修正これらのクラスを使用して、既存のquoteResponseクラスを交換するには:

class quoteResponse 
{ 
    public List<result> result { get; set; } 
} 

class rootObject 
{ 
    public quoteResponse quoteResponse { get; set; } 
} 

その後、代わりにquoteResponseクラスのrootObjectクラスにJSONをデシリアライズ:そこから

rootObject root = js.Deserialize<rootObject>(reviewConverted); 

resultは次のようになります。

result result = root.quoteResponse.result[0]; 

し、必要に応じて、あなたはその結果から個々のプロパティを抽出することができます。

Row.regularMarketChangePercent = result.regularMarketChangePercent; 
Row.regularMarketChange = result.regularMarketChange; 
// etc. 
+0

は...あなたの応答をありがとう、あなたは提案された変更をしようとした魅力のように働きました。 –

関連する問題