E
E
eskims2021-09-25 07:13:53
JSON
eskims, 2021-09-25 07:13:53

Check if element exists in json?

Good afternoon, how can I check the presence of " CurrentSeasonGamesNeededForRating " c Newtonsoft.Json in the received json?
json example

json
{
  "QueueSkills": {
    "competitive": {
      "CurrentSeasonGamesNeededForRating": 1,
      "SeasonalInfoBySeasonID": null
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris the Animal, 2021-09-25
@eskims

Make the property Nullable and if it is null, then the value did not come at all. I think this is the easiest option, if you are not happy with the default value of 0 for the int type, which will be so even if the value of that property does not even come.

public class Competitive
{
    [JsonProperty("CurrentSeasonGamesNeededForRating")]
    public int? CurrentSeasonGamesNeededForRating { get; set; }

    [JsonProperty("SeasonalInfoBySeasonID")]
    public object SeasonalInfoBySeasonID { get; set; }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question