我正在为我的网站使用 Json.Net。我希望序列化程序默认以驼峰形式序列化属性名称。我不希望它更改我手动分配的属性名称。我有以下代码:
public class TestClass
{
public string NormalProperty { get; set; }
[JsonProperty(PropertyName = "CustomName")]
public string ConfiguredProperty { get; set; }
}
public void Experiment()
{
var data = new TestClass { NormalProperty = null,
ConfiguredProperty = null };
var result = JsonConvert.SerializeObject(data,
Formatting.None,
new JsonSerializerSettings {ContractResolver
= new CamelCasePropertyNamesContractResolver()}
);
Console.Write(result);
}
的输出Experiment
是:
{"normalProperty":null,"customName":null}
但是,我希望输出为:
{"normalProperty":null,"CustomName":null}
这有可能实现吗?