JObject & CamelCase conversion with JSON.Net

前端 未结 4 893
忘掉有多难
忘掉有多难 2020-12-06 03:51

How can I convert a generic JObject to camelCase plain json string? I\'ve tried with JsonSerializerSettings but doesn\'t work (Newtonsoft.Json 4.5.11)

[Test]         


        
4条回答
  •  伪装坚强ぢ
    2020-12-06 04:28

    This question starts from a JObject and wants to work to a camel-cased JSON object. If you are actually starting from an object and want to get to a JObject that is already camelcased, then you can do this:

    var serializer = new JsonSerializer()
    {
        ContractResolver = new CamelCasePropertyNamesContractResolver()
    };
    var jo = JObject.FromObject(someDataContract, serializer);
    

    The resulting 'jo' will be camelcased.

提交回复
热议问题