Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从我的 ASP.NET MVC 3 应用程序返回一个 JSON 结果,如下所示:
{ 0: value1, 1: value2 }
但是我无法创建一个匿名类型的对象,该对象将数字作为字段名称。那么我能做什么呢?
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);
输出是
{"0":"value1","1":"value2"}