如何将通用 JObject 转换为 camelCase 纯 json 字符串?我试过 JsonSerializerSettings 但不起作用(Newtonsoft.Json 4.5.11)
[Test]
public void should_convert_to_camel_case()
{
var serializer = JsonSerializer.Create(new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
var jo = new JObject();
jo["CamelCase"] = 1;
var stringWriter = new StringWriter();
var writer = new JsonTextWriter(stringWriter);
serializer.Serialize(writer,jo);
var serialized = stringWriter.ToString();
Assert.AreEqual("{\"camelCase\":1}", serialized);
}
更新 根据http://json.codeplex.com/workitem/23853无法完成(tnx 到 @nick_w 的链接)