Search code examples
c#jsonjson.netgoogle-data-api

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


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# class with a variable name starting with a dollar sign, it's not allowed by the language. I'm using JSON.NET from Newtonsoft to convert JSON to C# objects. How can I get around this problem?


Solution

  • You could try using the [JsonProperty] attribute to specify the name:

    [JsonProperty(PropertyName = "$someName")]
    public string SomeName { get; set; }