C# JSON.NET convention that follows underscore gives me headact

34 views Asked by At

I have a post method response json body exactly like this:

[{
  "_routeId": "657a2fe455905539f9eed1a5",
  "distance": {
    "text": "859 km",
    "value": 859444
  },
  "duration": {
    "items": {
      "days": 0,
      "hours": 10,
      "minutes": 22,
      "seconds": 31
    },
    "text": "10hr 22min",
    "value": 37351
  }}]

So far, I can get duration field with my data transfer model but I couldn't get _routeId field. Here is my dto, I've tried JsonPropertyName already but I have not solved unfortunately.

public class DistanceMatrixResponseModel {
  [JsonProperty(PropertyName = "_routeId")]
  public string RouteId { get; set; }

  public RouteDistanceModel Distance { get; set; }

  public RouteDistanceModel Duration { get; set; }
}

What should I do?

So far, I have tried to get _ underscore fields with JsonPropertyName. duration fields is okay, but other field which name is _routeId returns null. I couldn't map each other.

0

There are 0 answers