小编mas*_*ata的帖子

使用枚举类型进行 JSON 反序列化

我正在尝试使用UnityEngine.JsonUtility. 它工作正常,但我的枚举类型没有得到正确转换。我尝试使用该EnumMember属性,但仍然没有运气。

我该如何解决?

笔记

我正在使用解决方案读取多个文件并将它们存储在数组中。

[Serializable]
public class EquipementItem
{
    public enum ItemTypes
    {
        None,
        Armor,
        Weapon
    }

    public enum SlotTypes
    {
        Head,
        Shoulders,
        Chest,
        Bracers,
        Gloves,
        Waist,
        Legs,
        Boots,
        Weapon
    }

    public int ID;
    public string Name;

    public ItemTypes ItemType;
    public SlotTypes SlotType;
}
Run Code Online (Sandbox Code Playgroud)

和 json 文件

{
"Items": [
{
  "ID": "1",
  "Name": "Basic Sword",
  "ItemType": "Weapon",
  "SlotType": "Weapon"
},
{
  "ID": "2",
  "Name": "Advanced Sword",
  "ItemType": "Weapon",
  "SlotType": "Weapon"
},
{ …
Run Code Online (Sandbox Code Playgroud)

c# enums json unity-game-engine

3
推荐指数
1
解决办法
9595
查看次数

标签 统计

c# ×1

enums ×1

json ×1

unity-game-engine ×1