I have this very simple method as below:
//my current file
using Newtonsoft.Json;
string key1 = \"FirstKey\";
string key2 = \"SecondKey\";
string key3 = \"Th
Getting some clue from @code4life's comment in accepted answer, I realized that it is achievable through JArray object as well found in Newtonsoft.Json.Linq namespace. So, I thought of building another answer to provide an alternative in case it helps someone:
using Newtonsoft.Json.Linq;
private string CreateJson(string val1, string val2, string val3, string val4, string val5, string val6)
{
var configs = new[]
{
new { FirstKey = val1, SecondKey = val2, ThirdKey = val3},
new { FirstKey = val4, SecondKey = val5, ThirdKey = val6}
};
return JArray.FromObject(configs).ToString();
}
Note: Anonymous types which are being created through new { FirstKey = val1, SecondKey = val2, ThirdKey = val3} syntax can very well contain any .Net data type for that matter and not just strings which I've asked in my original post e.g.new { FirstKey = "AnyString", SecondKey = true, ThirdKey = DateTime.Now}