Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to read Description, OutcomeDateTime, Team field which is inside Competitors array. I have tried JSON.Net but all the examples I found are pretty simple json feed but mine Json is quite complex. Can anyone suggest me how can I pull that fields into my C#?

{
   "State of Origin 2014":{
      "1471137":{
         "EventID":1471137,
         "ParentEventID":1471074,
         "MainEvent":"State Of Origin Series 2014",
         "Description":"Series Score - State Of Origin Series 2014",
         "Weather":null,
         "SuspendDateTime":"2014-06-18 20:10:00.0000000",
         "OutcomeDateTime":"2014-06-18 20:10:00.0000000",
         "Competition":"State of Origin 2014",
         "Competitors":{
            "ActiveCompetitors":3,
            "Competitors":[
               {
                  "Team":"New South Wales (2 - 1)",
                  "Win":"2.15",
                  "CompetitorID":8630871,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },
               {
                  "Team":"New South Wales (3 - 0)",
                  "Win":"3.05",
                  "CompetitorID":8630870,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },
               {
                  "Team":"Queensland (2 - 1)",
                  "Win":"3.30",
                  "CompetitorID":8630869,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               }
            ],
            "TotalCompetitors":3,
            "HasWinOdds":true
         },
         "EventStatus":"Open",
         "IsSuspended":false,
         "AllowBets":true
      },
      "1471074":{
         "EventID":1471074,
         "ParentEventID":0,
         "MainEvent":"State Of Origin Series 2014",
         "Description":"State Of Origin Series 2014",
         "Weather":null,
         "SuspendDateTime":"2014-06-18 20:10:00.0000000",
         "OutcomeDateTime":"2014-07-09 20:10:00.0000000",
         "Competition":"State of Origin 2014",
         "Competitors":{
            "ActiveCompetitors":2,
            "Competitors":[
               {
                  "Team":"New South Wales",
                  "Win":"1.33",
                  "CompetitorID":8630484,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },
               {
                  "Team":"Queensland",
                  "Win":"3.30",
                  "CompetitorID":8630483,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               }
            ],
            "TotalCompetitors":2,
            "HasWinOdds":true
         },
         "EventStatus":"Open",
         "IsSuspended":false,
         "AllowBets":true
      }
   },
   "State of Origin 2014 Game 2":{
      "3608662":{
         "EventID":3608662,
         "ParentEventID":3269132,
         "MainEvent":"New South Wales v Queensland",
         "Description":"5 Point Winning Margin - New South Wales v Queensland",
         "Weather":null,
         "SuspendDateTime":"2014-07-09 20:10:00.0000000",
         "OutcomeDateTime":"2014-06-18 20:10:00.0000000",
         "Competition":"State of Origin 2014 Game 2",
         "Competitors":{
            "ActiveCompetitors":39,
            "Competitors":[
               {
                  "Team":"New South Wales 6-10",
                  "Win":"4.70",
                  "CompetitorID":19153876,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },
               {
                  "Team":"Queensland 91+",
                  "Win":"201.00",
                  "CompetitorID":19153914,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               }
            ],
            "TotalCompetitors":39,
            "HasWinOdds":true
         },
         "EventStatus":"Open",
         "IsSuspended":false,
         "AllowBets":true
      },
      "3608676":{
         "EventID":3608676,
         "ParentEventID":3269132,
         "MainEvent":"New South Wales v Queensland",
         "Description":"1st Half Line Betting (-2) - New South Wales v Queensland",
         "Weather":null,
         "SuspendDateTime":"2014-07-09 20:10:00.0000000",
         "OutcomeDateTime":"2014-06-18 20:10:00.0000000",
         "Competition":"State of Origin 2014 Game 2",
         "Competitors":{
            "ActiveCompetitors":3,
            "Competitors":[
               {
                  "Team":"Queensland (+2)",
                  "Win":"1.96",
                  "CompetitorID":19153964,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },
               {
                  "Team":"New South Wales (-2)",
                  "Win":"2.04",
                  "CompetitorID":19153963,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },
               {
                  "Team":"Tie",
                  "Win":"10.00",
                  "CompetitorID":19153965,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               }
            ],
            "TotalCompetitors":3,
            "HasWinOdds":true
         },
         "EventStatus":"Open",
         "IsSuspended":false,
         "AllowBets":true
      },
      "2205961":{
         "EventID":2205961,
         "ParentEventID":1896054,
         "MainEvent":"NRL Premiership 2014",
         "Description":"NRL 2014 - To Make Grand Final",
         "Weather":null,
         "SuspendDateTime":"2014-06-20 19:45:00.0000000",
         "OutcomeDateTime":"2014-10-05 17:00:00.0000000",
         "Competition":"NRL",
         "Competitors":{
            "ActiveCompetitors":15,
            "Competitors":[
               {
                  "Team":"Sydney Roosters",
                  "Win":"2.15",
                  "CompetitorID":13332848,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               }

            ],
            "TotalCompetitors":15,
            "HasWinOdds":true
         },
         "EventStatus":"Open",
         "IsSuspended":false,
         "AllowBets":true
      }
   },
   "NRL Premiership Futures":{
      "1896054":{
         "EventID":1896054,
         "ParentEventID":0,
         "MainEvent":"NRL Premiership 2014",
         "Description":"NRL Premiership 2014",
         "Weather":null,
         "SuspendDateTime":"2014-06-20 19:45:00.0000000",
         "OutcomeDateTime":"2014-10-05 18:00:00.0000000",
         "Competition":"NRL Premiership Futures",
         "Competitors":{
            "ActiveCompetitors":16,
            "Competitors":[
               {
                  "Team":"Sydney Roosters",
                  "Win":"4.50",
                  "CompetitorID":11375024,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               },

               {
                  "Team":"Newcastle Knights",
                  "Win":"301.00",
                  "CompetitorID":11375033,
                  "Eliminated":false,
                  "OrderOfEntry":0,
                  "HasWinOdds":true,
                  "AllowBets":true,
                  "IsSuspended":false,
                  "EventStatus":"Open",
                  "Position":false
               }
            ],
            "TotalCompetitors":16,
            "HasWinOdds":true
         },
         "EventStatus":"Open",
         "IsSuspended":false,
         "AllowBets":true
      }
   }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
119 views
Welcome To Ask or Share your Answers For Others

1 Answer

var json = new WebClient().DownloadString("http://4gp.tw/b036/1402972549560.txt");
var obj = JObject.Parse(json);
var query =
    from JObject ev in obj.PropertyValues()
    from JObject evid in ev.PropertyValues()
    select new
    {
        Description = (string)evid["Description"],
        OutcomeDateTime = Convert.ToDateTime((string)evid["OutcomeDateTime"]),
        Teams =
            from JObject comps in evid["Competitors"]["Competitors"]
            select (string)comps["Team"],
    };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...