Deserialize JSON with dot in property name

前端 未结 2 1970
孤街浪徒
孤街浪徒 2021-01-18 10:43

I am trying to deserialize JSON with dots in the property names into a key-value format. I am using the inbuilt ASP.NET MVC model binding. It seems to be interpreting the do

2条回答
  •  渐次进展
    2021-01-18 11:36

    I came here looking for a way to deserialize a json string into a model, and while the question here is solved though the MVC framework, it did not solve my issue.

    Given a json string of

    {
       "Property.Something": "The value"
    }
    

    I found that using the [JsonProperty] attribute I could deserialize the string into my model like this:

    public class JsonModel
    {
       [JsonProperty(PropertyName = "Property.Something")]
       public string PropertySomething {get; set;}
    }
    

提交回复
热议问题