MR.ABC
MR.ABC

Reputation: 4862

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. Any idea ?

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

Upvotes: 2

Views: 367

Answers (1)

fcuesta
fcuesta

Reputation: 4520

Try using the JsonProperty attribute:

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

Upvotes: 5

Related Questions