I have to deserialize json into C# classes but many of the json field names have a forward slash in them.
I've searched this site to see if anyone else has asked a similar question but nothing came up.
json:
{
"start": "2019-10-24T10:37:27.590Z",
"end": "2019-10-24T11:00:00.000Z",
"requests/duration": {
"avg": 3819.55
}
}
c#
class Metrics
{
public DateTime start = DateTme.MinValue;
public DateTime end = DateTme.MinValue;
public RequestsDuration requestsduration = null;
}
class RequestsDuration
{
public double avg = 0.0;
}
...
Metrics data = JsonConvert.DeserializeObject<Metrics>(json);
The "requests/duration" in the json does not deserialize into the Metrics class.
I can do this before deserializing:
json = json.Replace("requests/duration","requestsduration")
but I was wondering if there was a cleaner way.
Does json.net provide a way to deal with special characters in json fields?