我有一个解析这个json的问题:
{
"product_info":
{
"title": "Product Name"
}
}
这是我的代码:
using UnityEngine;
using System.Collections;
using System.IO;
using System.Net;
using UnityEngine.UI;
public class ReadJson : MonoBehaviour
{
public Text myText;
[System.Serializable]
public class ProductInfo
{
public string title { get; set; }
}
[System.Serializable]
public class RootObject
{
public ProductInfo product_info { get; set; }
}
void Start () {
TextAsset asset = Resources.Load (Path.Combine ("Json", "toulouse")) as TextAsset;
RootObject m = JsonUtility.FromJson<RootObject> (asset.text);
Debug.Log (m.product_info.title);
}
}
我收到了这个错误信息:"对象引用未设置为对象的实例"。我已经尝试过成功解析一个非嵌套的JSON,但是现在我不明白为什么即使创建了适当的类也无法工作。