I've been trying to create nested arrays with C# Linq JSON library. Is there some reason why first way doesn't work but later one works.
using System;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
JObject jo = new JObject();
// Linq-way
jo.Add(new JProperty("Nested_failed", new JArray(
new JArray(
new JValue(0),
new JValue(false),
new JValue(21)
)
)
)
);
// Second try
JArray nested = new JArray();
nested.Add(new JArray(
new JValue(0),
new JValue(false),
new JValue(21)
)
);
jo.Add(new JProperty("Nested_succeed",nested));
Console.WriteLine(jo.ToString());
}
}
Results this
{
"Nested_failed": [
0,
false,
21
],
"Nested_succeed": [
[
0,
false,
21
]
]
}
As far as I can understand, both ways should end up to the same result. But for some reason nested JArray is skipped when you construct it in "Linq-way".