实现此目的的方法是在
JsonResult此处实现一个自定义:
创建自定义ValueType并使用自定义JsonResult进行序列化
(原始链接
无效
) 。
并使用替代的序列化程序,例如JSON.NET,它支持这种行为, 例如:
Product product = new Product{ ExpiryDate = new DateTime(2010, 12, 20, 18, 1, 0, DateTimeKind.Utc), Name = "Widget", Price = 9.99m, Sizes = new[] {"Small", "Medium", "Large"}};string json = JsonConvert.SerializeObject( product, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
结果是
{ "name": "Widget", "expiryDate": "/Date(1292868060000)/", "price": 9.99, "sizes": [ "Small", "Medium", "Large" ]}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)