我试图弄清楚是否可以将多个引用彼此的json文件解析为C#类结构。
示例:
类json文件
{
"wizard" :
{
"type" : "ice",
"spells" : ["ice_orb", "ice_storm"]
}
}
拼写json文件:
{
"spells" :
{
"ice_orb":
{
"damage": 25,
"cooldown": 2
},
"ice_storm":
{
"damage": 35,
"cooldown": 4
}
}
}
预期结果:
[Serializable]
public class IceOrb
{
public int damage;
public int cooldown;
}
[Serializable]
public class IceStorm
{
public int damage;
public int cooldown;
}
[Serializable]
public class Spell
{
public IceOrb ice_orb;
public IceStorm ice_storm;
}
[Serializable]
public class Wizard
{
public string type;
public List<Spell> spells;
}
请不要建议将所有内容合并到一个文件中,因为它不适合我。