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?
Syntax. do { statement(s); } while( condition ); Notice that the conditional expression appears at the end of the loop, so the statement(s) in the loop executes once before the condition is tested. If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop executes again.
You could try using the [JsonProperty]
attribute to specify the name:
[JsonProperty(PropertyName = "$someName")]
public string SomeName { get; set; }
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With