简体   繁体   English

MVC4 Web API返回带有特殊字符的json属性密钥字符串

[英]MVC4 Web API Return json propertykey strings with special characters

C# do not allows property names with special characters like space etc. Need to have a way to define json objects like this. C#不允许使用带有特殊字符(如空格等)的属性名称。需要有一种定义此类json对象的方法。 Any idea ? 任何想法 ?

{
   ".Class1 #Id1" : "Value1"
   ".Class1 #Id2" : "Value2"
}

Try using the JsonProperty attribute: 尝试使用JsonProperty属性:

        public class MyClass
        {
            [JsonProperty(".Class1 #Id1")]
            public string id1 { get; set; }
            [JsonProperty(".Class1 #Id2")]
            public string id2 { get; set; }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM