Reputation: 26976
I need to return a JSON result from my ASP.NET MVC 3 application like this:
{ 0: value1, 1: value2 }
But I can't create an object with anonymous type that would have numbers as field names. So what can I do?
Upvotes: 2
Views: 258
Reputation: 15673
var dict = new Dictionary<string,string>();
dict["0"] = "value1";
dict["1"] = "value2";
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var output = serializer.Serialize(dict);
The output is
{"0":"value1","1":"value2"}
Upvotes: 4