【发布时间】:2021-10-01 16:48:37
【问题描述】:
我正在尝试从 json 文件中仅获取一个对象,但不能。在检查器中,对象是空的,当我试图做某事时,该对象因为它是空的而得到空异常。我还尝试将我试图检索的对象放入列表中,但列表仍然是空的。我的错误在哪里? 我的 Json 文件如下所示:
{
"Dialogue": {
"npcName": "John",
"sentences": [
{
"text1": "Hello, come here",
"text2": "How do you feel",
"text3": " good bye!"
}
]
}
}
这是我的代码:
public TextAsset jsonScript;
public Dialogue dialogue;
void Start()
{
try
{
dialogue = JsonUtility.FromJson<Dialogue>(jsonScript.text);
}
catch (System.Exception error)
{
Debug.LogError(error);
}
}
对话类:
[System.Serializable]
public class Dialogue
{
public string npcName;
public string[] sentences;
}
【问题讨论】: