json序列化大小写问题
JsonProperty属性解决
public class UserInfo
{
[JsonProperty("id")]
public int Id{ set; get; }
[JsonProperty("userName")]
public string UserName{ set; get; }
}
使用newtonsoft.json来设置格式化的方式(推荐使用)
var user = new { Name = "john", Age = 19 };
var serializerSettings = new JsonSerializerSettings
{
// 设置为驼峰命名
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var userStr = JsonConvert.SerializeObject(user, Formatting.None, serializerSettings);