Sorry if this has been asked already, suppose I have an anonymous list of objects like this:
Collection = new List<object>() {
new {
FirstSetting = new
{
FirstKEy = "Property vs Inspections",
color = "#FF6384",
fontStyle = "Arial",
sidePadding = 10,
}
},
new {
AnotherSettings = new
{
text = "another text",
color = "#FF6384",
fontStyle = "Arial",
sidePadding = 10,
}
}
};
and would like to convert to a JSON string using
JsonConvert.SerializeObject(Collection, JsonSerializerSettings);
I get this result.
[{
"FirstSetting": {
"FirstKey": "Property vs Inspections",
"color": "#FF6384",
"fontStyle": "Arial",
"sidePadding": 10
}
}, {
"anotherSettings": {
"text": "another text",
"color": "#FF6384",
"fontStyle": "Arial",
"sidePadding": 10
}
}]
but I do not wish to have an array. I'd like to have each settings to be an object something like this.
{
"FirstSetting": {
"FirstKey": "Property vs Inspections",
"color": "#FF6384",
"fontStyle": "Arial",
"sidePadding": 10
},
"anotherSettings": {
"text": "another text",
"color": "#FF6384",
"fontStyle": "Arial",
"sidePadding": 10
}
}
could someone shed some light please?
Dictionary<string, object>and let the key be the names instead of using anonymous objects for that.