#Json issues

1 messages · Page 1 of 1 (latest)

echo lava
#

If I've this enum:

public enum Leary
{
    Aanvallen,    // Attack
    Leiden,       // Lead
    Verdedigen,   // Help
    Volgen,       // Follow
}

And this structure for it:

using System;

namespace DialogueSystem
{
    [Serializable]
    public class Wrapper
    {
        public Dialogue[] dialogues;
    }

    [Serializable]
    public class Dialogue
    {
        public int id;
        public int[] refIds;

        public Leary leary;

        public bool correct;

        public string speaker;
        public string text;
    }
}

And a sample out of the json loaded would be

{
  "dialogues": [
    {
      "id": 17,
      "correct": null,
      "speaker": "Peter",
      "leary": "Volgen",
      "text": "Laten we het proberen.",
      "refIds": null
    }
  ]
}

It should just be loaded correctly, no? Right now it just defaults everything to the first enum element, Aanvallen, so something with it being read with the JsonUtility is going wrong and I don't know what. Everything else does gets loaded correctly and has been working fine for a long time now

small spoke
#

Enums in Unity are serialized as integers

#

I would expect a number 0-3 for the enum in the json

echo lava
#

o, so not as string?

small spoke
#

no

echo lava
# small spoke no

So like every leary entry in my json I've to change to the matching integer instead?

echo lava
#

I looked up things but got confused somewhere and did it wrong ehheh