字符串未在SSIS/C#中使用regex替换进行更新



我正在尝试解析一个超级混乱的字符串,以便在SSIS中使用.NET 4.7中的脚本组件将其转换为有效的JSON(即"":"["product1","[\"product2\"","\"[\\\"[\\\\\\\"product3\\\\\\\"]\\\"]\"]"]""等(。SSIS包运行,但是,下面的代码没有对字符串jsonObj执行任何替换。我不明白为什么。

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
//set variables
string jsonObj = System.Text.Encoding.ASCII.GetString(Row.UNSTRUCTUREDVARS.GetBlobData(0,Convert.ToInt32(Row.UNSTRUCTUREDVARS.Length)));
string[] regExPattern = new string[] { "\\", "\d""", ""\[", """\[", "\]"", "}}""", """{", "}""", ":"{", "}"", "\]""" };
string[] replacePattern = new string[] { "", """, "[", "[", "]", "}}", "{", "}", ":{", "},", "]," };

for (int i = 0; i<regExPattern.Length; i++)
{
Regex rgx = new Regex(regExPattern[i]);
jsonObj = rgx.Replace(jsonObj, replacePattern[i]);
}

假设RegEx代码有效,则不会将值分配回行。因此,这些数据正在被遗忘。

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
//set variables    
string jsonObj = System.Text.Encoding.ASCII.GetString(Row.UNSTRUCTUREDVARS.GetBlobData(0,Convert.ToInt32(Row.UNSTRUCTUREDVARS.Length)));    
string[] regExPattern = new string[] { "\\", "\d""", ""\[", """\[", "\]"", "}}""", """{", "}""", ":"{", "}"", "\]""" };
string[] replacePattern = new string[] { "", """, "[", "[", "]", "}}", "{", "}", ":{", "},", "]," };
for (int i = 0; i<regExPattern.Length; i++)
{    
Regex rgx = new Regex(regExPattern[i]);
jsonObj = rgx.Replace(jsonObj, replacePattern[i]);
}
Row.UNSTRUCTUREDVARS = jsonObj;
}

最新更新