json序列化大小写问题

JsonProperty属性解决

  1. public class UserInfo
  2. {
  3. [JsonProperty("id")]
  4. public int Id{ set; get; }
  5. [JsonProperty("userName")]
  6. public string UserName{ set; get; }
  7. }

使用newtonsoft.json来设置格式化的方式(推荐使用)

  1. var user = new { Name = "john", Age = 19 };
  2. var serializerSettings = new JsonSerializerSettings
  3. {
  4. // 设置为驼峰命名
  5. ContractResolver = new CamelCasePropertyNamesContractResolver()
  6. };
  7. var userStr = JsonConvert.SerializeObject(user, Formatting.None, serializerSettings);

参考文章