Yes, I'm using assemblies pertaining to the use of System.Text.Json:
- System.Text.Json version 4.0.1.0
- System.Buffers.dll version 4.0.2.0
- System.Memory.dll version 4.0.1.1
Refer to https://learn.microsoft.com/en-us/answers/questions/414330/how-to-set-up-the-use-of-systemtextjson-within-a-s.html
Here's the script code:
public void Main()
{
// TODO: Add your code here
const string curlResponseCode = "CurlResponseCode";
const string taskOutputArrayName = "PackageIdArray";
try
{
var stream = new FileStream(Dts.Connections["TeamworkCloudModelElementJsonOne"].ConnectionString, FileMode.Open);
JsonDocument document = JsonDocument.Parse(stream);
stream.Close();
ArrayList packageIdArray = new ArrayList();
foreach (JsonElement kermlOwnedElement in document.RootElement[1].GetProperty("kerml:ownedElement").EnumerateArray())
{
packageIdArray.Add(kermlOwnedElement.GetProperty("@id").GetString());
}
if (Dts.Variables.Contains(taskOutputArrayName))
Dts.Variables[taskOutputArrayName].Value = packageIdArray;
else
throw new ApplicationException("Missing variable to set: " + taskOutputArrayName);
document.Dispose();
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.Events.FireError(ex.HResult, string.Empty, "Exception thrown: " + ex.Message, string.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
finally
{
bool fireAgain = false;
if (Dts.Variables.Contains(curlResponseCode))
Dts.Events.FireInformation(0, string.Empty, "Curl Response Code: " + Dts.Variables[curlResponseCode].Value, string.Empty, 0, ref fireAgain);
}
}