I am new to C# and I am trying to create an object in a similar way that we create them in js:
var obj = {
'method' : 'connect',
'data' : {
'somekey' : 'data',
'somekey2' : 'data',
'somekey3' : 'data',
'somekey4' : 'data'
}};
Eventually this will be converted into JSON. So far I have tried using a dictionary like this:
connect.Method = "connect";
connect.Data = new Dictionary<string, object>();
connect.Data.Add("data", new Dictionary<string, object>()
{
{ "somekey", "data" },
{ "somekey2", "data" },
{ "somekey3", "data" },
{ "somekey4", "data" }
}
);
but doing that in the json output it looks like:
{ "Method":"connect", "Data":{ "data":{ "somekey":"data", "somekey2":"data", "somekey3":"data", "somekey4":"data"} } }
Which is problematic because the M in method shouldn't be capitalized (its that way because how I defined the class I am sure I can fix this one myself.
The main issue is the extra "Data" that is getting added into the JSON.
Does anyone have any ideas of a better way to do this, I am trying to avoid just using huge strings to convert into JSON.