I need to serialize a list of objects, but not using the "default way":
Let's say I have this class in C#:
public class Test
{
public string Key;
public string Value;
}
List<Test> tests;
If I serialize this list (return Json(tests.ToArray())
) I get this
{"Key": "vKey1", "Value": "value1"}, {"Key": "vKey2", "Value": "value2"}
Instead of that, I want this result:
{"vKey1": "value1"}, {"vKey2": "value2"}
EDIT:
This is the desired output:
{"vKey1": "value1", "vKey2": "value2"}
I want the first variable's content to be the JS property name and the second one its value.
Any ideas? I've seen this solution:
How do I convert a dictionary to a JSON String in C#?
but I don't wanna transform my object list into a dictionary so I could transform it again using that string.format solution.
Thanks!