将嵌套的json统一在一起

Sil*_*ing 4 c# json unity-game-engine

我有一个解析这个json的问题:

{
    "product_info":
    {
        "title": "Product Name"
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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);

    }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:"对象引用未设置为对象的实例".我已经尝试过,成功地解析了一个没有嵌套的json但是我不明白为什么但是在创建了适当的类之后仍然无法工作.

Eve*_*rts 9

JsonUtility不支持属性.只需删除{get; 组;}

[System.Serializable]
public class ProductInfo
{
    public string title;
}

[System.Serializable]
public class RootObject
{
    public ProductInfo product_info;
}
Run Code Online (Sandbox Code Playgroud)