Return json with lower case first letter of property names

前端 未结 4 1970
走了就别回头了
走了就别回头了 2021-02-01 17:43

I have LoginModel:

public class LoginModel : IData
{
    public string Email { get; set; }
    public string Password { get; set; }
}

and I hav

4条回答
  •  無奈伤痛
    2021-02-01 18:08

    If you need it only in some certain place and not throughout whole application, then you can do following:

    var objectToSerialize = new {Property1 = "value1", SubOjbect = new { SubObjectId = 1 }};
    var json = Newtonsoft.Json.JsonConvert.SerializeObject(data, new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() });
    

    It should result in {"property1":"value1","subOjbect":{"subObjectId":1}} (note that nested properties also starts from lowercase)

提交回复
热议问题