How do C# classes deal with dollar signs in JSON?

前端 未结 3 1788
轻奢々
轻奢々 2020-12-03 17:32

I\'m getting a JSON feed from Google\'s data API and a lot of the property names start with a $ character (dollar sign).

My problem is that I can\'t create a C# clas

3条回答
  •  我在风中等你
    2020-12-03 18:02

    firas489 was on the right track that $ indicates metadata, not an actual data field. However the fix is actually to do this:

    JsonSerializerSettings settings = new JsonSerializerSettings();
    settings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;            
    

    Set the metadata handling to ignore, and then you can serialize/deserialize the property using the PropertyName attribute:

    [JsonProperty("$id")]
    public string Id { get; set; }
    

提交回复
热议问题