0

These are my classes

<pre>///Thank you for helping me....
  public class Sport
    {
        public string id { get; set; }
        public string name { get; set; }
    }
    public class Category
    {
        public string id { get; set; }
        public string name { get; set; }
        public string country_code { get; set; }
    }

    public class Competition
    {
        public string id { get; set; }
        public string name { get; set; }
    }
    public class Season
    {
        public string id { get; set; }
        public string name { get; set; }
        public string start_date { get; set; }
        public string end_date { get; set; }
        public string year { get; set; }
        public string competition_id { get; set; }
    }
    public class Stage
    {
        public int order { get; set; }
        public string type { get; set; }
        public string phase { get; set; }
        public string start_date { get; set; }
        public string end_date { get; set; }
        public string year { get; set; }
    }
    public class Round
    {
        public int number { get; set; }
        public string other_sport_event_id { get; set; }
        public int cup_round_sport_event_number { get; set; }
        public int cup_round_number_of_sport_events { get; set; }
    }

    public class Group
    {
        public string id { get; set; }
        public string name { get; set; }
    }

    public class SportEventContext
    {
        public Sport sport { get; set; }
        public Category category { get; set; }
        public Competition competition { get; set; }
        public Season season { get; set; }
        public Stage stage { get; set; }
        public Round round { get; set; }
        public IList<Group> groups { get; set; }
    }

    public class SportEventProperties
    {
        public bool lineups { get; set; }
        public bool extended_player_stats { get; set; }
        public bool extended_team_stats { get; set; }
        public bool ballspotting { get; set; }
        public bool commentary { get; set; }
        public bool fun_facts { get; set; }
        public bool goal_scorers { get; set; }
        public string scores { get; set; }
        public bool game_clock { get; set; }
        public bool deeper_play_by_play { get; set; }
        public bool deeper_player_stats { get; set; }
        public bool deeper_team_stats { get; set; }
        public bool basic_play_by_play { get; set; }
        public bool basic_player_stats { get; set; }
        public bool basic_team_stats { get; set; }
        public string lineups_availability { get; set; }
    }

    public class Coverage
    {
        public string type { get; set; }
        public SportEventProperties sport_event_properties { get; set; }
    }

    public class Competitor
    {
        public string id { get; set; }
        public string name { get; set; }
        public string country { get; set; }
        public string country_code { get; set; }
        public string abbreviation { get; set; }
        public string qualifier { get; set; }
        public string gender { get; set; }
        public Statistics statistics { get; set; }
    }

    public class Ground
    {
        public bool neutral { get; set; }
    }
    public class Referee
    {
        public string id { get; set; }
        public string name { get; set; }
        public string nationality { get; set; }
        public string country_code { get; set; }
        public string type { get; set; }
    }

    public class SportEventConditions
    {
        public Ground ground { get; set; }
        public IList<Referee> referees { get; set; }
    }

    public class Venue
    {
        public string id { get; set; }
        public string name { get; set; }
        public int capacity { get; set; }
        public string city_name { get; set; }
        public string country_name { get; set; }
        public string map_coordinates { get; set; }
        public string country_code { get; set; }
    }

    public class SportEvent
    {
        public string id { get; set; }
        public DateTime start_time { get; set; }
        public bool start_time_confirmed { get; set; }
        public SportEventContext sport_event_context { get; set; }
        public Coverage coverage { get; set; }
        public IList<Competitor> competitors { get; set; }
        public SportEventConditions sport_event_conditions { get; set; }
        public Venue venue { get; set; }
    }

    public class PeriodScore
    {
        public int home_score { get; set; }
        public int away_score { get; set; }
        public string type { get; set; }
        public int number { get; set; }
    }

    public class Clock
    {
        public string played { get; set; }
    }

    public class SportEventStatus
    {
        public string status { get; set; }
        public string match_status { get; set; }
        public int home_score { get; set; }
        public int away_score { get; set; }
        public IList<PeriodScore> period_scores { get; set; }
        public Clock clock { get; set; }
    }
    public class Statistics
    {
        public int yellow_cards { get; set; }
        public int yellow_red_cards { get; set; }
        public int red_cards { get; set; }
        public int corner_kicks { get; set; }
        public int shots_total { get; set; }
        public int shots_on_target { get; set; }
        public int shots_off_target { get; set; }
        public int shots_blocked { get; set; }
        public int ball_possession { get; set; }
        public int free_kicks { get; set; }
        public int offsides { get; set; }
        public int goal_kicks { get; set; }
        public int throw_ins { get; set; }
        public int shots_saved { get; set; }
        public int fouls { get; set; }
        public int injuries { get; set; }
        public int cards_given { get; set; }
        public int substitutions { get; set; }
    }



    public class Totals
    {
        public IList<Competitor> competitors { get; set; }
    }



    public class Summary
    {
        public SportEvent sport_event { get; set; }
        public SportEventStatus sport_event_status { get; set; }
        public Statistics statistics { get; set; }
    }

    public class SoccerInformation
    {

        public DateTime generated_at { get; set; }
        public IList<Summary> summaries { get; set; }

        
    }
</pre>


And the some of the json data


<pre>
 "summaries": [
        {
            "sport_event": {
                "id": "sr:sport_event:24534090",
                "start_time": "2020-11-23T12:00:00+00:00",
                "start_time_confirmed": true,
                "sport_event_context": {
                    "sport": {
                        "id": "sr:sport:1",
                        "name": "Futbol"
                    },
                    "category": {
                        "id": "sr:category:297",
                        "name": "Azerbaycan",
                        "country_code": "AZE"
                    },
                    "competition": {
                        "id": "sr:competition:709",
                        "name": "Premier Lig"
                    },
                    "season": {
                        "id": "sr:season:77839",
                        "name": "Premier Lig 20\/21",
                        "start_date": "2020-08-21",
                        "end_date": "2021-05-31",
                        "year": "20\/21",
                        "competition_id": "sr:competition:709"
                    },
                    "stage": {
                        "order": 1,
                        "type": "league",
                        "phase": "regular season",
                        "start_date": "2020-08-21",
                        "end_date": "2021-05-31",
                        "year": "20\/21"
                    },
                    "round": {
                        "number": 10
                    },
                    "groups": [
                        {
                            "id": "sr:league:51295",
                            "name": "Premier League 20\/21"
                        }
                    ]
                },
                "coverage": {
                    "type": "sport_event",
                    "sport_event_properties": {
                        "lineups": false,
                        "extended_player_stats": false,
                        "extended_team_stats": false,
                        "ballspotting": false,
                        "commentary": false,
                        "fun_facts": true,
                        "goal_scorers": true,
                        "scores": "live",
                        "game_clock": true,
                        "deeper_play_by_play": false,
                        "deeper_player_stats": false,
                        "deeper_team_stats": false,
                        "basic_play_by_play": false,
                        "basic_player_stats": false,
                        "basic_team_stats": false
                    }
                },
                "competitors": [
                    {
                        "id": "sr:competitor:382568",
                        "name": "Sabah FC",
                        "country": "Azerbaycan",
                        "country_code": "AZE",
                        "abbreviation": "SBH",
                        "qualifier": "home",
                        "gender": "male"
                    },
                    {
                        "id": "sr:competitor:281393",
                        "name": "Sabail FK",
                        "country": "Azerbaycan",
                        "country_code": "AZE",
                        "abbreviation": "SAB",
                        "qualifier": "away",
                        "gender": "male"
                    }
                ],
                "sport_event_conditions": {
                    "ground": {
                        "neutral": false
                    }
                }
            },
            "sport_event_status": {
                "status": "closed",
                "match_status": "ended",
                "home_score": 2,
                "away_score": 1,
                "winner_id": "sr:competitor:382568",
                "period_scores": [
                    {
                        "home_score": 2,
                        "away_score": 0,
                        "type": "regular_period",
                        "number": 1
                    },
                    {
                        "home_score": 0,
                        "away_score": 1,
                        "type": "regular_period",
                        "number": 2
                    }
                ]
            },
            "statistics": {
                "totals": {
                    "competitors": [
                        {
                            "id": "sr:competitor:382568",
                            "name": "Sabah FC",
                            "abbreviation": "SBH",
                            "qualifier": "home",
                            "statistics": {
                                "yellow_cards": 2,
                                "cards_given": 2,
                                "substitutions": 3,
                                "corner_kicks": 3,
                                "injuries": 1
                            }
                        },
                        {
                            "id": "sr:competitor:281393",
                            "name": "Sabail FK",
                            "abbreviation": "SAB",
                            "qualifier": "away",
                            "statistics": {
                                "yellow_cards": 1,
                                "cards_given": 1,
                                "substitutions": 4,
                                "corner_kicks": 4
                            }
                        }
                    ]
                }
            }
        }
</pre>


and i used to json to c# these codes:

<pre>
var content = await result.Content.ReadAsStringAsync();///Thank you for helping me....
                
return JsonConvert.DeserializeObject<SoccerInformation>(content);///Thank you

im trying to list matches to learn how to get datas from json to .net core mvc i deserialized json to c# object via using the json2c# website but i can't reach the some of the classes like

  • name of the competitors one by one...
  • first period scores and scond period scores

im trying to do this at the view part of the MVC i send the model but i can't list them via using Foreach loop in the view.

mko1995
  • 15
  • 3
  • Does this answer your question? [How do I turn a C# object into a JSON string in .NET?](https://stackoverflow.com/questions/6201529/how-do-i-turn-a-c-sharp-object-into-a-json-string-in-net) – Mojtaba Ahmadi Nov 23 '20 at 22:20

1 Answers1

0
  1. First verify that your json string adheres to the 'SoccerInformation' class. I don't find a generated_at field in your json.
  2. Secondly, verify that all your json Keys are same as your class property names.
  3. Thirdly, try accessing these with JObject.