Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 我可以使用CamelCasePropertyNamesContractResolver来CamelCase字符串吗?_.net_Json_Asp.net Web Api2 - Fatal编程技术网

.net 我可以使用CamelCasePropertyNamesContractResolver来CamelCase字符串吗?

.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

有没有办法重用CamelCasePropertyNamesContractResolver将属性名转换为字符串的方法

我使用CamelCasePropertyNamesContractResolver作为WebApi的JsonFormatter,它工作得非常好。在我的应用程序的另一个方面,我动态地将一些.NET模型属性转换为字符串,以便在JS中使用。但是,字符串是Pascal大小写(就像我的.NET标准一样),因此在JS中不能用于直接针对已格式化的JS对象属性

// 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);
    }
}