(); //返回数据 return readData; } //解析Json数据 public void ParseData(string jsonData) { //数据解析并把数据保存到m_PersonData1 变量中 Data m_PersonData = JsonUtility.FromJson<Data>(jsonData); foreach (var item in m_PersonData.Person) { Debug.Log(item.Name); Debug.Log(item.Grade)...
private void ReadJson02() { // 获取json文件中所有的文字(json文件需要是 UTF8 编码) string data = File.ReadAllText(Application.streamingAssetsPath + "/Question.json", System.Text.Encoding.UTF8); // 将文字转换为本类中的字段 JsonUtility.FromJsonOverwrite(data, this); // 将读取的内容打印到控制...
string jsonData = ReadData(); Debug.Log(jsonData); Data m_PersonData = JsonUtility.FromJson<Data>(jsonData); Debug.Log(m_PersonData.Person.Name); Debug.Log(m_PersonData.Person.Grade); } //读取文件 public string ReadData() { string readData = ""; string fileUrl = Application.streamin...
sw.Close(); JsonPath= WindowsDirectory +"Config.json"; }#endifReadMyJson(); }//读取方法publicstaticvoidReadMyJson() {stringjsonString =File.ReadAllText(JsonPath); TestSetting mytest= JsonUtility.FromJson<TestSetting>(jsonString); test=mytest; Port=mytest.Port; CutTime=mytest.CutTime; exeX...
Unity 读取.Json内容 1 usingSystem;usingSystem.IO;usingUnityEngine;publicclassReadJson:MonoBehaviour {publicstaticTestSetting test =newTestSetting();//文件路径publicstaticstringtestJsonPath;publicstaticintPort;publicstaticintCutTime;publicstaticintexeX;publicstaticintexeY;publicstaticintexeWhith;publicstaticint...
先看看,在Unity中,我们在其Json工具类中,可用的函数,总共就5个,好少啊!不过,simple is better. #region 程序集 UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // H:\Unity\Project\JsonReadTest\Library\UnityAssemblies\UnityEngine.dll ...
[SetUp]publicvoidSetup(){jsonReader=newGameObject().AddComponent<JsonReader>();jsonReader.jsonFile=...
讲道理Unity自带的JsonUtility库在Unity5之后就已经实装,而且性能也强,但是无奈网上的博客大多都是各种复读机,以致于国内我看好多帖子用的都是第三方的Json库。 要使用 JsonUtility 不用额外导入名字空间,这个类下面,我们能使用的一共就三个接口 JsonUtility接口 其中FromJson 是反序列化,用于将Json文件读取到我们所指定...
string json = ""; if (!File.Exists(filepath)) { Debug.LogError("玩家数据文件缺失"); } using (StreamReader sr = new StreamReader(filepath)) { json = sr.ReadToEnd(); Debug.Log(json); sr.Close(); } return JsonUtility.FromJson<T>(json); ...
这里用到JSON.serialized方法,其目的是将JSON数据序列化,进而使用Encoding.UTF8的方式保存数据。保存的格式可以是txt或者json。 读取JSON文件 首先添加获取本地文件的方法,因为之前我将文件保存在Resources文件夹下,因此获取地址也是写死的(不建议)。 voidLoadJsonFromFile(refJSONjson){TextAssettxt=Resources.Load("_av...