2

我在 SSIS 的脚本组件中有以下代码。

我正在尝试反序列化 JSON 输出并将响应输出到数据库。

反序列化部分正在返回响应。

输出检查点

但是,我得到一个“对象引用未设置为对象的实例”。OutputBuffer.AddRow() 上的错误;

在此处输入图像描述

我在兜圈子。我究竟做错了什么?

public class ScriptMain : UserComponent
{

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

        string vOpportunityURL = Variables.pardotopportunityurl;
        System.Windows.Forms.MessageBox.Show(vOpportunityURL);

        int vMaxOpportunityId = Variables.pardotopportunitymaxid;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vMaxOpportunityId));

        int vProcessedRecordCount = Variables.pardotrecordcnt;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vProcessedRecordCount));

        var vProcessDate = Variables.pardotprocessdt;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vProcessDate));

        RootObject oppOutputResponse = GetWebServiceResult(vOpportunityURL);

        foreach (Opportunity op in oppOutputResponse.result.opportunity)
        {

            OpportunityDataBuffer.AddRow();
            OpportunityDataBuffer.ID = op.id;
            System.Windows.Forms.MessageBox.Show(Convert.ToString(op.id));
            OpportunityDataBuffer.Name = op.name;
            System.Windows.Forms.MessageBox.Show(Convert.ToString(op.name));

        }


    }


    private RootObject GetWebServiceResult(string vOpportunityURL)
    { 
        // Create API WEeb Service Request

        HttpWebRequest opportunityFullDataReq = (HttpWebRequest)WebRequest.Create(vOpportunityURL);

        var opportunityDataPostStr = "user_key=";
            opportunityDataPostStr += Variables.pardotauthusrkey;
            opportunityDataPostStr += "&api_key=";
            opportunityDataPostStr += Variables.pardotapikey;
            opportunityDataPostStr += "&output=full";
            opportunityDataPostStr += "&format=json";
            opportunityDataPostStr += "&sort_by=id";
            opportunityDataPostStr += "&sort_order=ascending";
            opportunityDataPostStr += "&id_greater_than=";
            opportunityDataPostStr += Variables.pardotopportunitymaxid;

            System.Windows.Forms.MessageBox.Show(Convert.ToString(opportunityDataPostStr));
            System.Windows.Forms.MessageBox.Show(vOpportunityURL + Convert.ToString(opportunityDataPostStr));

        var opportunityPostStream = Encoding.ASCII.GetBytes(opportunityDataPostStr);

        opportunityFullDataReq.Method = "POST";
        opportunityFullDataReq.ContentType = "application/x-www-form-urlencoded";
        opportunityFullDataReq.ContentLength = opportunityPostStream.Length;

        using(var opportunityStream = opportunityFullDataReq.GetRequestStream())
        {
            opportunityStream.Write(opportunityPostStream, 0, opportunityPostStream.Length);
        }

        // Capture Web Service Respose

        HttpWebResponse opportunityFullDataResponse = (HttpWebResponse)opportunityFullDataReq.GetResponse();

        RootObject opportunityWSResponse = null;

        Stream opportunityJsonStream = opportunityFullDataResponse.GetResponseStream();
        string wsResponseString = null;

        using (StreamReader wsResponseReader = new StreamReader(opportunityJsonStream))
        {
            wsResponseString = wsResponseReader.ReadToEnd();
            wsResponseReader.Close();
        }

        JavaScriptSerializer wsResponseJson = new JavaScriptSerializer();

        //var serialJsonResponseString = wsResponseJson.Serialize(wsResponseString);
        System.Windows.Forms.MessageBox.Show(wsResponseString.ToString());

        opportunityWSResponse = wsResponseJson.Deserialize<RootObject>(wsResponseString);

        return opportunityWSResponse;
   }
4

1 回答 1

1

PostExecute 中不存在输出缓冲区。

在调用方法将内容添加到缓冲区之前,您可以检查最后一行是否已通过缓冲区。

这里有类似的问题:我可以在 PostExecute 的 SSIS 脚本组件中向输出缓冲区添加行吗?

于 2021-07-08T18:23:36.547 回答