I'm using a JSON file for loading texts and dialogs and here's my JSON file:
{
"Story":
[
{"Name":"FirstEncounter", "Content":[
{"id":0, "text":"sample"},
{"id":1, "text":"sample2"}
]},
{"Name":"LaGrandDuel", "Content":[
{"id":0, "text":"sample"},
{"id":1, "text":"sample2"}
]}
],
"Quest1":
[
{"Name":"FirstEncounter", "Content":[
{"id":0, "text":"sample"},
{"id":1, "text":"sample2"}
]},
{"Name":"QuestDetail", "Content":[
{"id":0, "text":"sample"},
{"id":1, "text":"sample2"}
]}
]
}
And I can load it using JsonUtility
like this:
private void Start()
{
Texts = Resources.Load<TextAsset>("Texts/Test").text;
Root JsonData = JsonUtility.FromJson<Root>(Texts);
}
and here are the classes I use:
[System.Serializable]
public class Content
{
public int id;
public string text;
}
[System.Serializable]
public class Story
{
public string Name;
public List<Content> Content;
}
[System.Serializable]
public class Quest1
{
public string Name;
public List<Content> Content;
}
[System.Serializable]
public class Root
{
public List<Story> Story;
public List<Quest1> Quest1;
}
So setting up the whole thing is done. But, for instance, how can I access the Content
related to FirstEncounter
in Story
? Root
and Story
classes use a list, not a dictionary. So I'm completely clueless about how to access different contents.
Sorry if the question seems a bit silly, I'm pretty new to JSON files.