C#JSON.net -Array like- Object非常量名称对象的反序列化

时间:2014-03-22 19:36:52

标签: c# json object deserialization

我正在尝试反序列化下面的json:

{
    "raw": {
        "435": {
            "clubId": 435,
            "name": "Last Gladiators",
            "seasons": 154,
            "titlesWon": "21",
            "leaguesWon": "0",
            "divsWon1": 10,
            "divsWon2": -4,
            "divsWon3": 6,
            "divsWon4": 10,
            "cupsWon1": "1",
            "cupsWon2": "1",
            "cupsWon3": "1",
            "cupsWon4": "0",
            "dblsWon1": "1",
            "dblsWon2": "1",
            "dblsWon3": "1",
            "dblsWon4": "0",
            "cupsElim1": "1",
            "cupsElim2": "7",
            "cupsElim3": "25",
            "cupsElim4": "0",
            "promotions": "47",
            "holds": "66",
            "relegations": "41",
            "currentPoints": "9329",
            "currentDivision": "7",
            "prevDivision": "6",
            "maxDivision": "10",
            "bestDivision": 1,
            "bestPoints": "4",
            "curSeasonMov": "-2",
            "lastMatch0": "2",
            "lastMatch1": "0",
            "lastMatch2": "1",
            "lastMatch3": "0",
            "lastMatch4": "2",
            "lastMatch5": "2",
            "lastOpponent0": "34703",
            "lastOpponent1": "69960",
            "lastOpponent2": "781",
            "lastOpponent3": "57091",
            "lastOpponent4": "70263",
            "lastOpponent5": "59048",
            "starLevel": "10",
            "cupRankingPoints": "324",
            "overallRankingPoints": "9653",
            "alltimeGoals": "2141",
            "alltimeGoalsAgainst": "2111",
            "seasonWins": "3",
            "seasonTies": "2",
            "seasonLosses": "2",
            "gamesPlayed": "7",
            "goals": "16",
            "goalsAgainst": "10",
            "points": "11",
            "projectedPoints": "15",
            "prevSeasonWins": "2",
            "prevSeasonTies": "2",
            "prevSeasonLosses": "2",
            "prevPoints": "8",
            "prevProjectedPts": "13",
            "skill": "32",
            "wins": "548",
            "ties": "301",
            "losses": "606"
        },
        "72388": {
            "clubId": 72388,
            "name": "Last Kings ",
            "seasons": 0,
            "titlesWon": "0",
            "leaguesWon": "0",
            "divsWon1": 10,
            "divsWon2": 10,
            "divsWon3": 10,
            "divsWon4": 10,
            "cupsWon1": "0",
            "cupsWon2": "0",
            "cupsWon3": "0",
            "cupsWon4": "0",
            "dblsWon1": "0",
            "dblsWon2": "0",
            "dblsWon3": "0",
            "dblsWon4": "0",
            "cupsElim1": "0",
            "cupsElim2": "0",
            "cupsElim3": "0",
            "cupsElim4": "0",
            "promotions": "0",
            "holds": "0",
            "relegations": "0",
            "currentPoints": "1",
            "currentDivision": "1",
            "prevDivision": "1",
            "maxDivision": "1",
            "bestDivision": 0,
            "bestPoints": "0",
            "curSeasonMov": "-2",
            "lastMatch0": "0",
            "lastMatch1": "1",
            "lastMatch2": "-1",
            "lastMatch3": "-1",
            "lastMatch4": "-1",
            "lastMatch5": "-1",
            "lastOpponent0": "72179",
            "lastOpponent1": "72384",
            "lastOpponent2": "-1",
            "lastOpponent3": "-1",
            "lastOpponent4": "-1",
            "lastOpponent5": "-1",
            "starLevel": "1",
            "cupRankingPoints": "0",
            "overallRankingPoints": "1",
            "alltimeGoals": "2",
            "alltimeGoalsAgainst": "6",
            "seasonWins": "0",
            "seasonTies": "1",
            "seasonLosses": "1",
            "gamesPlayed": "2",
            "goals": "2",
            "goalsAgainst": "6",
            "points": "1",
            "projectedPoints": "-1",
            "prevSeasonWins": "0",
            "prevSeasonTies": "1",
            "prevSeasonLosses": "0",
            "prevPoints": "1",
            "prevProjectedPts": "-1",
            "skill": "1",
            "wins": "0",
            "ties": "1",
            "losses": "1"
        },
        "71361": {
            "clubId": 71361,
            "name": "Last Lap Mtsprt",
            "seasons": 0,
            "titlesWon": "0",
            "leaguesWon": "0",
            "divsWon1": 10,
            "divsWon2": 10,
            "divsWon3": 10,
            "divsWon4": 10,
            "cupsWon1": "0",
            "cupsWon2": "0",
            "cupsWon3": "0",
            "cupsWon4": "0",
            "dblsWon1": "0",
            "dblsWon2": "0",
            "dblsWon3": "0",
            "dblsWon4": "0",
            "cupsElim1": "1",
            "cupsElim2": "0",
            "cupsElim3": "0",
            "cupsElim4": "0",
            "promotions": "0",
            "holds": "0",
            "relegations": "0",
            "currentPoints": "1",
            "currentDivision": "1",
            "prevDivision": "1",
            "maxDivision": "1",
            "bestDivision": 0,
            "bestPoints": "0",
            "curSeasonMov": "-2",
            "lastMatch0": "0",
            "lastMatch1": "1",
            "lastMatch2": "0",
            "lastMatch3": "0",
            "lastMatch4": "0",
            "lastMatch5": "-1",
            "lastOpponent0": "72226",
            "lastOpponent1": "66842",
            "lastOpponent2": "71280",
            "lastOpponent3": "70071",
            "lastOpponent4": "71366",
            "lastOpponent5": "-1",
            "starLevel": "1",
            "cupRankingPoints": "5",
            "overallRankingPoints": "6",
            "alltimeGoals": "4",
            "alltimeGoalsAgainst": "12",
            "seasonWins": "0",
            "seasonTies": "1",
            "seasonLosses": "4",
            "gamesPlayed": "5",
            "goals": "4",
            "goalsAgainst": "12",
            "points": "1",
            "projectedPoints": "2",
            "prevSeasonWins": "0",
            "prevSeasonTies": "1",
            "prevSeasonLosses": "3",
            "prevPoints": "1",
            "prevProjectedPts": "2",
            "skill": "1",
            "wins": "0",
            "ties": "1",
            "losses": "4"
        },
        "68341": {
            "clubId": 68341,
            "name": "LAST LEGENDS",
            "seasons": 1,
            "titlesWon": "1",
            "leaguesWon": "0",
            "divsWon1": 10,
            "divsWon2": 10,
            "divsWon3": 10,
            "divsWon4": 10,
            "cupsWon1": "0",
            "cupsWon2": "0",
            "cupsWon3": "0",
            "cupsWon4": "0",
            "dblsWon1": "0",
            "dblsWon2": "0",
            "dblsWon3": "0",
            "dblsWon4": "0",
            "cupsElim1": "0",
            "cupsElim2": "0",
            "cupsElim3": "0",
            "cupsElim4": "0",
            "promotions": "1",
            "holds": "0",
            "relegations": "0",
            "currentPoints": "50",
            "currentDivision": "2",
            "prevDivision": "1",
            "maxDivision": "2",
            "bestDivision": 10,
            "bestPoints": "12",
            "curSeasonMov": "-2",
            "lastMatch0": "1",
            "lastMatch1": "2",
            "lastMatch2": "1",
            "lastMatch3": "1",
            "lastMatch4": "0",
            "lastMatch5": "0",
            "lastOpponent0": "68584",
            "lastOpponent1": "67494",
            "lastOpponent2": "68821",
            "lastOpponent3": "68670",
            "lastOpponent4": "63245",
            "lastOpponent5": "67555",
            "starLevel": "2",
            "cupRankingPoints": "0",
            "overallRankingPoints": "50",
            "alltimeGoals": "18",
            "alltimeGoalsAgainst": "19",
            "seasonWins": "0",
            "seasonTies": "1",
            "seasonLosses": "0",
            "gamesPlayed": "1",
            "goals": "3",
            "goalsAgainst": "3",
            "points": "1",
            "projectedPoints": "-1",
            "prevSeasonWins": "0",
            "prevSeasonTies": "0",
            "prevSeasonLosses": "0",
            "prevPoints": "0",
            "prevProjectedPts": "-1",
            "skill": "4",
            "wins": "3",
            "ties": "4",
            "losses": "3"
        },
        "41220": {
            "clubId": 41220,
            "name": "Last Xmas",
            "seasons": 10,
            "titlesWon": "8",
            "leaguesWon": "0",
            "divsWon1": 10,
            "divsWon2": 7,
            "divsWon3": 8,
            "divsWon4": 10,
            "cupsWon1": "0",
            "cupsWon2": "0",
            "cupsWon3": "0",
            "cupsWon4": "0",
            "dblsWon1": "0",
            "dblsWon2": "0",
            "dblsWon3": "0",
            "dblsWon4": "0",
            "cupsElim1": "0",
            "cupsElim2": "0",
            "cupsElim3": "0",
            "cupsElim4": "0",
            "promotions": "8",
            "holds": "2",
            "relegations": "0",
            "currentPoints": "1852",
            "currentDivision": "9",
            "prevDivision": "9",
            "maxDivision": "9",
            "bestDivision": 2,
            "bestPoints": "17",
            "curSeasonMov": "-2",
            "lastMatch0": "0",
            "lastMatch1": "0",
            "lastMatch2": "2",
            "lastMatch3": "0",
            "lastMatch4": "2",
            "lastMatch5": "2",
            "lastOpponent0": "2132",
            "lastOpponent1": "776",
            "lastOpponent2": "3896",
            "lastOpponent3": "941",
            "lastOpponent4": "2851",
            "lastOpponent5": "373",
            "starLevel": "8",
            "cupRankingPoints": "0",
            "overallRankingPoints": "1852",
            "alltimeGoals": "201",
            "alltimeGoalsAgainst": "105",
            "seasonWins": "6",
            "seasonTies": "0",
            "seasonLosses": "3",
            "gamesPlayed": "9",
            "goals": "15",
            "goalsAgainst": "14",
            "points": "18",
            "projectedPoints": "20",
            "prevSeasonWins": "6",
            "prevSeasonTies": "0",
            "prevSeasonLosses": "2",
            "prevPoints": "18",
            "prevProjectedPts": "22",
            "skill": "27",
            "wins": "60",
            "ties": "14",
            "losses": "12"
        },
        "42282": {
            "clubId": 42282,
            "name": "LastManStanding",
            "seasons": 0,
            "titlesWon": "0",
            "leaguesWon": "0",
            "divsWon1": 10,
            "divsWon2": 10,
            "divsWon3": 10,
            "divsWon4": 10,
            "cupsWon1": "0",
            "cupsWon2": "0",
            "cupsWon3": "0",
            "cupsWon4": "0",
            "dblsWon1": "0",
            "dblsWon2": "0",
            "dblsWon3": "0",
            "dblsWon4": "0",
            "cupsElim1": "0",
            "cupsElim2": "0",
            "cupsElim3": "0",
            "cupsElim4": "0",
            "promotions": "0",
            "holds": "0",
            "relegations": "0",
            "currentPoints": "3",
            "currentDivision": "1",
            "prevDivision": "1",
            "maxDivision": "1",
            "bestDivision": 0,
            "bestPoints": "0",
            "curSeasonMov": "-2",
            "lastMatch0": "2",
            "lastMatch1": "0",
            "lastMatch2": "-1",
            "lastMatch3": "-1",
            "lastMatch4": "-1",
            "lastMatch5": "-1",
            "lastOpponent0": "39619",
            "lastOpponent1": "37433",
            "lastOpponent2": "-1",
            "lastOpponent3": "-1",
            "lastOpponent4": "-1",
            "lastOpponent5": "-1",
            "starLevel": "1",
            "cupRankingPoints": "0",
            "overallRankingPoints": "3",
            "alltimeGoals": "3",
            "alltimeGoalsAgainst": "3",
            "seasonWins": "1",
            "seasonTies": "0",
            "seasonLosses": "1",
            "gamesPlayed": "2",
            "goals": "3",
            "goalsAgainst": "3",
            "points": "3",
            "projectedPoints": "-1",
            "prevSeasonWins": "0",
            "prevSeasonTies": "0",
            "prevSeasonLosses": "1",
            "prevPoints": "0",
            "prevProjectedPts": "-1",
            "skill": "1",
            "wins": "1",
            "ties": "0",
            "losses": "1"
        }
    }
}

正如您在json的树状视图中所看到的那样:http://prntscr.com/335ctx 服务器返回一个主“原始”对象,该对象包含零到多个对象,每个对象随机命名一个大范围内的数字,并且每个对象都有一些其他常量对象。

我的基类是:

public class ReSearchResponse
{
    public Raw2 raw { get; set; }
}

Raw2类应该包含一些东西,它告诉获取并保存“原始”对象的所有对象

通过这样做:

public class Raw2
{
    [JsonProperty(PropertyName="41220")]
    public Raw item {get; set;}
}

“item”成功获取从服务器发送的所有数据,但仅限于服务器返回名为“41220”的对象时。

欢迎任何帮助。

1 个答案:

答案 0 :(得分:0)

假设Raw是表示{"clubId": 41220, "name": "Last Xmas" ... }的数据类型,您实际尝试反序列化的是Dictionary<int, Raw>

我还没有对此进行测试,但您可以尝试使用以下内容:

public class ReSearchResponse
{
    public Dictionary<int, Raw> Data { get; set; }
}