【问题标题】:SimpleJSON in Unity not parsingUnity中的SimpleJSON不解析
【发布时间】:2020-07-17 13:52:38
【问题描述】:

我正在尝试使用 SimpleJSON 在 Unity 中解析 .json 文件,但解析返回 null。

我的解析器类:

[SerializeField]
private string phrasesFileJSON = "conversations.json";

private JSONNode data;

public void Init () {
    string jsonFile = phrasesFileJSON.Replace (".json", "");

    TextAsset jsonObj = Resources.Load<TextAsset> (jsonFile);        
    data = JSONNode.Parse (jsonObj.ToString ());

    Debug.Log ("Data null? " + !data);
    Debug.Log (jsonObj.ToString());
}

调试打印:

Data null? True

{
  "0-0": {
    "speech": "Hello! This is a test phrase.",
    "keyword": "Mountain"
  }
}

所以文件被正确读取,但 JSONNode 无法解析它。谁能帮帮我?

【问题讨论】:

    标签: c# json unity3d


    【解决方案1】:

    文件被正确读取,JSONNode 正确解析它。

    但是,在您的 Debug.Log 中,您将 data 隐式转换为 bool,您使用的库已经覆盖了默认行为。

    如果你想检查JSONNode是否包含数据,你应该使用.Count

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      相关资源
      最近更新 更多