我如何轉換的通用JObject到駝峯純JSON字符串? 我試着JsonSerializerSettings但不工作(Newtonsoft.Json 4.5.11)JObject與駝峯轉換與JSON.Net
[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);
}
UPDATE 根據http://json.codeplex.com/workitem/23853不能做(TNX到@nick_w的鏈接)
不認爲序列化+反序列化+序列化過於高效。 – 2013-02-27 11:47:14
作爲解決方法我已經從JObject轉換到Dictionary。 –
2013-02-27 11:48:04
@AndreaBalducci查看我的編輯。 – 2013-02-27 19:49:06