CamelCasePropertyNamesContractResolver做了多少驼色分类?



使用JSON。像这样:

JsonConvert.SerializeObject(someObject, 
                            Newtonsoft.Json.Formatting.None, 
                            new JsonSerializerSettings() {
                                NullValueHandling = NullValueHandling.Ignore,
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                                ContractResolver = new CamelCasePropertyNamesContractResolver()
                            });

JSON。净做什么?

只是从单词开头开始的小写字母吗?

例子:

  • somePropertyId>somePropertyId
  • somePropertyID>somePropertyID
  • SOMEPropertyID>SOMEPropertyID
  • SOMEPROPERTYID>SOMEPROPERTYID

CamelCasePropertyNamesContractResolver直接从单元测试中做的是:https://github.com/JamesNK/Newtonsoft.Json/blob/95665429a431364327b4bce5332c39fda7819e7b/Src/Newtonsoft.Json.Tests/Utilities/StringUtilsTests.cs#L40-L54

[Test]
public void ToCamelCaseTest()
{
  Assert.AreEqual("urlValue", StringUtils.ToCamelCase("URLValue"));
  Assert.AreEqual("url", StringUtils.ToCamelCase("URL"));
  Assert.AreEqual("id", StringUtils.ToCamelCase("ID"));
  Assert.AreEqual("i", StringUtils.ToCamelCase("I"));
  Assert.AreEqual("", StringUtils.ToCamelCase(""));
  Assert.AreEqual(null, StringUtils.ToCamelCase(null));
  Assert.AreEqual("iPhone", StringUtils.ToCamelCase("iPhone"));
  Assert.AreEqual("person", StringUtils.ToCamelCase("Person"));
  Assert.AreEqual("iPhone", StringUtils.ToCamelCase("IPhone"));
  Assert.AreEqual("i Phone", StringUtils.ToCamelCase("I Phone"));
  Assert.AreEqual(" IPhone", StringUtils.ToCamelCase(" IPhone"));
}

相关内容

  • 没有找到相关文章