c#JSON.net - 编写用于反序列化的自定义类

时间:2017-08-27 09:47:02

标签: c# json

我正在尝试为某些JSON编写反序列化类。

    {
"runes": [
    {
        "rune_id": 12735222258,
        "wizard_id": 19886616,
        "occupied_type": 2,
        "occupied_id": 0,
        "slot_no": 1,
        "rank": 5,
        "class": 5,
        "set_id": 1,
        "upgrade_limit": 15,
        "upgrade_curr": 12,
        "base_value": 203490,
        "sell_value": 11305,
        "pri_eff": [
            3,
            99
        ],
        "prefix_eff": [
            1,
            250
        ],
        "sec_eff": [
            [
                9,
                5,
                0,
                0
            ],
            [
                2,
                17,
                0,
                0
            ],
            [
                4,
                10,
                0,
                0
            ],
            [
                8,
                4,
                0,
                0
            ]
        ],
        "extra": 0
    }
]
}

我有符文工作,但问题在于sec_eff。

有4个号码。第一个实际上需要是一个字符串。

我已经列出了多个字典,提供了数字。

这是我写的,我正在寻找正确的反序列化方法。

    public class RuneStats
{
    public string sStatType { get; set; }
    public int iValue { get; set; }
    public int iValue2 { get; set; }
    public int iValue3 { get; set; }
}

public class StatGroups
{
    private readonly cMapping _Maps = new cMapping();
    private RuneStats m_First { get; set; }
    public RuneStats First
    {
        get
        {
            return m_First;
        }
        set
        {

            int _value = Convert.ToInt32(value[0].ToString());
            m_First.sStatType = _Maps.Stats[_value];
        }
    }
    public RuneStats Second { get; set; }
    public RuneStats Third { get; set; }
    public RuneStats Fourth { get; set; }
    public int extra { get; set; }
}
public class Rune
{
    public long rune_id { get; set; }
    public int wizard_id { get; set; }
    public int occupied_type { get; set; }
    public long occupied_id { get; set; }
    public int slot_no { get; set; }
    public int rank { get; set; }
    public int _class { get; set; }
    public int set_id { get; set; }
    public int upgrade_limit { get; set; }
    public int upgrade_curr { get; set; }
    public int base_value { get; set; }
    public int sell_value { get; set; }
    public int[] pri_eff { get; set; }
    public int[] prefix_eff { get; set; }
    public StatGroups sec_eff { get; set; }
    public int extra { get; set; }
}

我无法访问值[0]。

我希望能够让第一个数字成为字典中的字符串。

0 个答案:

没有答案