我正在查看JSON.NET和ServiceStack.Text以將POCO對象序列化爲JSON。 JSON.NET似乎非常靈活,但性能成本有點低。 ServiceStack.Text似乎提供幾乎所有我需要的更好的性能。這確實是ServiceStack顯得缺乏的只有一件事......我可以配置ServiceStack.Text以將枚舉值序列化爲camelCase嗎?
如果我有一個包含一個枚舉屬性的對象,說象下面的枚舉...
public enum PersonStatus
{
ActiveAgent,
InactiveAgent
}
public class Person
{
//A bunch of other properties
public PersonStatus Status { get; set; }
}
如果我設置ServiceStack配置序列化使用駝峯使用以下代碼:
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
我最終狀態屬性序列如下:
種狀態:活性試劑
注意,屬性名是駱駝,但枚舉值是PascalCase。
無論我使用ServiceStack.Text的JsonSerializer
還是TypeSerializer
,此行爲似乎一致。
ServiceStack中是否有一種簡單的方法來更改此行爲,以使該值也是camelCase?
感謝您的快速反應!結束了由於我無法控制的其他原因而去JSON.NET,但我喜歡ServiceStack.Text的簡易性和性能。 – 2012-03-06 20:32:52
@mythz你知道是否有方法來實例化JsonSerializer並將配置應用於該實例嗎? – 2017-01-27 14:12:42