c#json按键合并子

时间:2016-08-22 22:37:06

标签: c# json merge

txtOdds.txt:

{
 "events": [
   {
     "id":629087820,
     "awayScore":3.0, "homeScore":2.0,
     "awayRedCards":0.0, "homeRedCards":0.0,
     "periods":[
       {
         "lineId":330076348, "number":0, "cutoff":"08/22/2016 22:00:00",
         "maxSpread":12000.0, "maxTotal":12000.0,
         "spreads":[
           { "hdp":-0.25, "home":1.757, "away":2.19, "altLineId":null }
         ],
        "totals":[
          { "points":5.75, "over":1.74, "under":2.19, "altLineId":null }
        ],
        "maxMoneyline":4000.0,
        "maxTeamTotal":null,
        "moneyline":{"home":6.8,"away":1.699,"draw":3.06},
        "teamTotal":null
       }
     ],
     "starts":null, "home":null, "away":null,
     "rotNum":null, "liveStatus":0, "status":null,
     "parlayRestriction":0
   }
 ],
 "id":2196, "name":null, "homeTeamType":null,
 "hasOfferings":false, "container":null, "allowRoundRobins":false,
 "leagueSpecialsCount":0, "eventSpecialsCount":0, "eventCount":0
}

txtLeagues.txt

{
  "events":null,
  "id":2196, "name":"Spain - La Liga", "homeTeamType":"Team1",
  "hasOfferings":true, "container":"Spain", "allowRoundRobins":true,
  "leagueSpecialsCount":0, "eventSpecialsCount":0, "eventCount":11
}

我想将odds.txt解析为object,然后通过解析txtLeagues.txt来更新联盟名称。

这是我的代码:

    JsonMergeSettings setting = new JsonMergeSettings();
    setting.MergeArrayHandling = MergeArrayHandling.Merge;

    string txtodds = txtOdds();
    var Odds = JObject.Parse(txtodds);
    var OddsObject = Odds.ToObject<PSLeague>();


    string txtleagues = txtLeagues();
    JObject Leagues = JObject.Parse(txtleagues);
    var LeaguesObject = Leagues.ToObject<PSLeague>();

    Odds.Merge(Leagues, setting);


    var test = Odds.ToObject<PSLeague>();

无论我选择MergeArrayHandling到Concat还是Replace或Merge或Union,它都没有用,有什么建议吗?

0 个答案:

没有答案