Mümkün mü?Camelcase JavaScriptSerializer ile nasıl zorlanır?
Böyle bir sınıf var:
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; }
}
Ama bunun yerine { "Name":"foo", "AnotherField":"bar" }
bu { "name":"foo", "anotherField":"bar" }
gibi serialize istiyorum.
Bu
kullandığım nasıl:return Request.CreateResponse(HttpStatusCode.OK, new JavaScriptSerializer().Serialize(obj));
yardımcı olmalı: http://stackoverflow.com/questions/4671044/deserializing-json-responses-which-contain-attributes-that-conflict-with -kelime. Ve evet, açık bir şekilde, seri hale getirilmiş diziciden çıkmanız gerektiği anlamına geliyor. –
JSON.NET kullanıyorsanız, "CamelCasePropertyNamesContractResolver" özelliği ile bir örnek için http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization adresine bakın. Web.Api –
Bu, aşağıdakilerin bir kopyası olabilir: http://stackoverflow.com/questions/15040838/mvc-jsonresult-camelcase-serialization –