Click or drag to resize
Json.NETCreate JSON using Collection Initializers
 

This sample creates JObject and JArray instances using the C# collection initializer syntax.

Sample
Usage
 1JObject o = new JObject
 2{
 3    { "Cpu", "Intel" },
 4    { "Memory", 32 },
 5    {
 6        "Drives", new JArray
 7        {
 8            "DVD",
 9            "SSD"
10        }
11    }
12};
13
14Console.WriteLine(o.ToString());
15// {
16//   "Cpu": "Intel",
17//   "Memory": 32,
18//   "Drives": [
19//     "DVD",
20//     "SSD"
21//   ]
22// }