Reputation: 9015
In my MVC-4 Web-API server, I receive a Json string that contains spaces in it's names:
{ "field name" : "some value" , "simpleName" : "some string" }
I defined a Model
class, e.g:
public class SomeJsonModel
{
[DataMember(Name = "field name")]
public string FieldName { get; set; }
public string SimpleName { get; set; }
}
Now SimpleName
passes through (in spite it's first letter capitalization mismatch, which is good), but FieldName
becomes null
.
How can I successfully receive Json that has spaces in it's fields' names (predefined - I cannot change the client data source) ?
Upvotes: 0
Views: 1023
Reputation: 10175
Try adding [DataContract] on your class:
[DataContract]
public class SomeJsonModel
{
[DataMember(Name = "field name")]
public string FieldName { get; set; }
[DataMember]
public string SimpleName { get; set; }
}
Here is more info about this:
Upvotes: 2