代码
/// <summary>
/// 转json格式,序列化,首字母小写
/// [JsonConverter(typeof(StringEnumConverter))]
/// </summary>
/// <returns></returns>
public static string ToJsonLower(this object source)
{
if (source == null)
{
return string.Empty;
}
var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
return JsonConvert.SerializeObject(source, Formatting.None, serializerSettings);
}
调用
class Program
{
static void Main(string[] args)
{
var Moel = new Model() { A=3,B=3,C=3};
var res = Moel.ToJsonLower();
Console.WriteLine(res);
Console.ReadKey();
}
}
public class Model
{
public int A { get; set; }
public int B { get; set; }
public int C { get; set; }
public string DD { get; set; }
}
结果