Deserialize json that has some property name starting with a number

You should use JSON.NET or similar library that offers some more advanced options of deserialization. With JSON.NET all you need is adding JsonProperty attribute and specify its custom name that appears in resulting JSON. Here is the example:

   public class MyClass
   {
        [JsonProperty(PropertyName = "24hhigh")]
        public string Highest { get; set; }
        ...

Now to deserialize:

    string jsonData = ...    
    MyClass deserializedMyClass = JsonConvert.DeserializeObject<MyClass>(jsonData);

Leave a Comment

tech