I am trying to create a C# objects for the JSON response in my application. I have the JSON like below
 {
"@odata.context": "https://example.com/odata/$metadata#REQ",
"value": [
    {
        "Id": 17,
        "Name": "Req"
    }
  ]
 }
I am not sure how to create C# object for the @odata.context
public class RootObject
    {
        public string @odata.context { get; set; }
        public List<Value> value { get; set; }
    }
It throws error in @odata.context
That's because identifiers in C# can't have @ sign. You haven't stated what library you're using, but if it's JSON.NET then you can simply decorate the properties.
public class Root
{
    [JsonProperty("@odata.context")]
    public string OdataContext { get; set; }
    [JsonProperty("value")]
    public List<Value> Value { get; set; }
}
public class Value
{
    [JsonProperty("Id")]
    public long Id { get; set; }
    [JsonProperty("Name")]
    public string Name { 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