.net 我可以使用CamelCasePropertyNamesContractResolver来CamelCase字符串吗?
有没有办法重用CamelCasePropertyNamesContractResolver将属性名转换为字符串的方法 我使用CamelCasePropertyNamesContractResolver作为WebApi的JsonFormatter,它工作得非常好。在我的应用程序的另一个方面,我动态地将一些.NET模型属性转换为字符串,以便在JS中使用。但是,字符串是Pascal大小写(就像我的.NET标准一样),因此在JS中不能用于直接针对已格式化的JS对象属性.net 我可以使用CamelCasePropertyNamesContractResolver来CamelCase字符串吗?,.net,json,asp.net-web-api2,.net,Json,Asp.net Web Api2,有没有办法重用CamelCasePropertyNamesContractResolver将属性名转换为字符串的方法 我使用CamelCasePropertyNamesContractResolver作为WebApi的JsonFormatter,它工作得非常好。在我的应用程序的另一个方面,我动态地将一些.NET模型属性转换为字符串,以便在JS中使用。但是,字符串是Pascal大小写(就像我的.NET标准一样),因此在JS中不能用于直接针对已格式化的JS对象属性 // JS Example var
// JS Example
var myJsonObject = getJsonObjectFromServer();
var myPropertyString = getPropertyNameFromServer();
var value = myJsonObject[myPropertyString];
// But value cannot be determined as casing of myPropertyString has changed
我希望避免创建自己的ToCamelCase方法,因为它可能会创建不同的字符串。我还想继续使用CamelCasePropertyNamesContractResolver(问题的根源),因为应用程序现在相当大,需要大量的JS更新,使我的JS成为非标准的。在
public string JsonPropertyName
{
get
{
var resolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
return resolver.GetResolvedPropertyName(PropertyName);
}
}