-1

我有一个 JSON 数据字符串,我通过 webrequest 在线检索到该字符串。我正在尝试解析字符串并将数据映射到我的数据结构上,但它不起作用......我之前也对其他映射使用了相同的方法,到目前为止效果很好。但在这种特殊情况下,它不起作用..

这是我检索到的 JSON 格式的字符串:

{"Item":{"FirstName":"Antônio","LastName":"da Silva","CommonName":null,"Height":"175","DateOfBirth":{"Year":"1978","Month":"6","Day":"13"},"PreferredFoot":"Left","ClubId":"1825","LeagueId":"20","NationId":"54","Rating":"70","Attribute1":"53","Attribute2":"68","Attribute3":"74","Attribute4":"73","Attribute5":"55","Attribute6":"56","Rare":"1","ItemType":"PlayerM"}}

这是我解析字符串的类:

public class ParsePlayerInfo
{
    private PlayerClass playerInfo;

    public PlayerClass parse(string stringToParse)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        if ((stringToParse != null) && (stringToParse.Length > 0))
        {
            this.playerInfo = serializer.Deserialize<PlayerClass>(stringToParse);
        }
        return this.playerInfo;
    }
}

这是我的播放器类:

public class PlayerClass
{
    public PlayerClass()
    {
        this.Player = new PlayerContents();
    }

    public PlayerContents Player { get; set; }
}

这是我的播放器内容类:

public class PlayerContents
{
    public PlayerContents()
    {
        string str;
        this.ItemType = str = "";
        this.Rare = str = str;
        this.Attribute6 = str = str;
        this.Attribute5 = str = str;
        this.Attribute4 = str = str;
        this.Attribute3 = str = str;
        this.Attribute2 = str = str;
        this.Attribute1 = str = str;
        this.Rating = str = str;
        this.NationId = str = str;
        this.LeagueId = str = str;
        this.ClubId = str = str;
        this.PreferredFoot = str = str;
        this.Height = str = str;
        this.CommonName = str = str;
        this.FirstName = this.LastName = str;
        this.DateOfBirth = new DOB();
    }

    public string Attribute1 { get; set; }

    public string Attribute2 { get; set; }

    public string Attribute3 { get; set; }

    public string Attribute4 { get; set; }

    public string Attribute5 { get; set; }

    public string Attribute6 { get; set; }

    public string ClubId { get; set; }

    public string CommonName { get; set; }

    public DOB DateOfBirth { get; set; }

    public string FirstName { get; set; }

    public string Height { get; set; }

    public string ItemType { get; set; }

    public string LastName { get; set; }

    public string LeagueId { get; set; }

    public string NationId { get; set; }

    public string PreferredFoot { get; set; }

    public string Rare { get; set; }

    public string Rating { get; set; }
}

编辑:

这是我的 DOB 课程:

public class DOB
{
    public DOB()
    {
        this.Year = this.Month = this.Day;
    }

    public string Day { get; set; }

    public string Month { get; set; }

    public string Year { get; set; }
}

有任何想法吗?

4

1 回答 1

1

尝试重命名您的Player属性以匹配 JSON 中的属性,即Item

于 2013-02-20T09:59:21.993 回答