Skip to content

Commit

Permalink
Added Support for directly looping json arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jan 9, 2020
1 parent 1263074 commit 21db3f1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions taskt/Core/Automation/Commands/BeginListLoopCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ public override void RunCommand(object sender, Core.Script.ScriptAction parentCo
{
listToLoop = ((DataTable)complexVariable.VariableValue).Rows;
}
else if ((complexVariable.VariableValue.ToString().StartsWith("[")) && (complexVariable.VariableValue.ToString().EndsWith("]")) && (complexVariable.VariableValue.ToString().Contains(",")))
{
//automatically handle if user has given a json array
Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.JsonConvert.DeserializeObject(complexVariable.VariableValue.ToString()) as Newtonsoft.Json.Linq.JArray;

var itemList = new List<string>();
foreach (var item in jsonArray)
{
var value = (Newtonsoft.Json.Linq.JValue)item;
itemList.Add(value.ToString());
}

complexVariable.VariableValue = itemList;
listToLoop = itemList;
}
else
{
throw new Exception("Complex Variable List Type<T> Not Supported");
Expand Down

0 comments on commit 21db3f1

Please sign in to comment.