8

可能吗?

我有这样的课:

public class ABC
{
    [Key]
    [ScriptIgnore]
    public int Id { get; set; }

    public string Name { get; set; }

    public string AnotherField { get; set; }

    [ScriptIgnore]
    public virtual User User { get; set; }
}

但我想像这样序列化{ "name":"foo", "anotherField":"bar" }而不是 { "Name":"foo", "AnotherField":"bar" }.

这就是我的使用方式:

return Request.CreateResponse(HttpStatusCode.OK, new JavaScriptSerializer().Serialize(obj));
4

1 回答 1

-6

您可以使用来自 Newtonsoft.Json.Serialization 的骆驼案例解析器;在您的 global.asax 上,您在应用程序启动时注册它

using Newtonsoft.Json.Serialization;

protected void Application_Start()
{
     config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
于 2013-07-17T13:20:53.823 回答