Skip to content

Commit 7371e3e

Browse files
rasmuseegreedmclean
authored andcommitted
ContextActivities was unable to parse when items was object and not array.
1 parent c090627 commit 7371e3e

1 file changed

Lines changed: 39 additions & 8 deletions

File tree

TinCan/ContextActivities.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,60 @@ public ContextActivities(JObject jobj)
3535
if (jobj["parent"] != null)
3636
{
3737
parent = new List<Activity>();
38-
foreach (JObject jactivity in jobj["parent"]) {
39-
parent.Add((Activity)jactivity);
38+
if(jobj["parent"].Type == JTokenType.Array)
39+
{
40+
foreach (JObject jactivity in jobj["parent"]) {
41+
parent.Add((Activity)jactivity);
42+
}
43+
}
44+
else
45+
{
46+
parent.Add((Activity)jobj["parent"]);
4047
}
4148
}
4249
if (jobj["grouping"] != null)
4350
{
4451
grouping = new List<Activity>();
45-
foreach (JObject jactivity in jobj["grouping"]) {
46-
grouping.Add((Activity)jactivity);
52+
if (jobj["grouping"].Type == JTokenType.Array)
53+
{
54+
foreach (JObject jactivity in jobj["grouping"])
55+
{
56+
grouping.Add((Activity)jactivity);
57+
}
58+
}
59+
else
60+
{
61+
grouping.Add((Activity)jobj["grouping"]);
4762
}
4863
}
4964
if (jobj["category"] != null)
5065
{
5166
category = new List<Activity>();
52-
foreach (JObject jactivity in jobj["category"]) {
53-
category.Add((Activity)jactivity);
67+
if (jobj["category"].Type == JTokenType.Array)
68+
{
69+
foreach (JObject jactivity in jobj["category"])
70+
{
71+
category.Add((Activity)jactivity);
72+
}
73+
}
74+
else
75+
{
76+
category.Add((Activity)jobj["category"]);
5477
}
5578
}
5679
if (jobj["other"] != null)
5780
{
5881
other = new List<Activity>();
59-
foreach (JObject jactivity in jobj["other"]) {
60-
other.Add((Activity)jactivity);
82+
if (jobj["other"].Type == JTokenType.Array)
83+
{
84+
foreach (JObject jactivity in jobj["other"])
85+
{
86+
other.Add((Activity)jactivity);
87+
}
88+
}
89+
else
90+
{
91+
other.Add((Activity)jobj["other"]);
6192
}
6293
}
6394
}

0 commit comments

Comments
 (0)