If I have an IDictionary<string, string> MyDictionary
that resembles this:
{
{"foo", "bar"},
{"abc", "xyz"}
}
and in my MVC controller I have a method like so:
[HttpPost]
public JsonResult DoStuff()
{
return Json(MyDictionary);
}
...it sends back something like:
[
{"Key":"foo", "Value":"bar"},
{"Key":"abc", "Value":"xyz"}
]
I was expecting (and wanting) something like:
{
"foo":"bar",
"abc":"xyz"
}
How can I accomplish this?
UPDATE
So this is directly related to the fact that this project was upgraded from an ASP.NET 2.0 application that used a custom JSON serializer; apparently, for backwards compatibility, they made that the default JSON serializer in the MVC application. Ultimately I overrode that behavior in my controller with the Json.NET result, and my problem was solved.