I have a need to serialize a list of objects in a specific way:
Imagine I have the following C# class:
public class Test
{
public string Key;
public string Value;
}
List<Test> tests;
When I serialize this list (return Json(tests.ToArray())
) it results in:
{"Key": "vKey1", "Value": "value1"}, {"Key": "vKey2", "Value": "value2"}
Instead, I am looking for the output to be:
{"vKey1": "value1"}, {"vKey2": "value2"}
UPDATE:
This is the desired outcome:
{"vKey1": "value1", "vKey2": "value2"}
I want the content of the first variable to be the property name in JavaScript and the second one to be its value.
Any suggestions? I have looked into this solution:
How do I convert a dictionary to a JSON String in C#?
However, I would like to avoid converting my object list into a dictionary just to transform it using that string.format method.
Thank you!