unity 用LitJson类库解析json文件方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using LitJson;
using System.Text;


public class parsejson : MonoBehaviour {

   


    void Start () {
        

        ParseJson(Application.streamingAssetsPath + "/Hint.ini");
	}
	

	void Update () {

      

	}

    public void ParseJson(string path)
    {
        bool isTxists = File.Exists(path);

        if (isTxists)
        {

            string josntxt = File.ReadAllText(path,Encoding.Default);
            Root HintsClass = JsonMapper.ToObject<Root>(josntxt);  //得到josn类


            Debug.Log(HintsClass.Hints[0].Hint);


        }else
        {
            Debug.Log("文件不存在");
        }

    }




}


public class Hints
{

    public string Hint { get; set; }
}



public class Root
{

    public List<Hints> Hints { get; set; }
}

猜你喜欢

转载自blog.csdn.net/weixin_37744986/article/details/80492819