using System.IO;using UnityEngine;publicclassFileReadTest:MonoBehaviour{voidUpdate(){//当按下鼠标左键时if(Input.GetMouseButtonDown(0)){StartCoroutine(ReadData());}}/// /// IO读取/// /// <returns></returns>privateIEnumeratorReadData(){string readData;string fileUrl=Application.streamingAssetsPath...
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...
privateIEnumeratorReadData() { stringreadData; stringfileUrl=Application.streamingAssetsPath+"/FileReadTest.json"; //读取文件 using(StreamReadersr=File.OpenText(fileUrl)) { //数据保存 readData=sr.ReadToEnd(); sr.Close(); } //返回数据 Debug.Log("打印读取的技能Json:"+readData); yieldreturnnu...
string json = JsonUtility.ToJson(m_PersonData); AlterData(json); } //读取文件 public string ReadData() { //string类型的数据常量 string readData; //获取到路径 string fileUrl = Application.streamingAssetsPath + "\\jsonInfo.json"; //读取文件 using (StreamReader sr = File.OpenText(fileUrl))...
先看看,在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 ...
Json文件很简单,内容如下: 第一种:System.IO读取本地文件 这种方法是比较常用的一种,通过IO流的StreamReader方法进行文件读取。需要导入命名空间System.IO; 这也是C#语言读取文件的一种常用方式。 示例代码如下: usingSystem.IO;usingUnityEngine;publicclassFileReadTest:MonoBehaviour{voidUpdate(){//当按下鼠标左键...
private void ParseJson(string fileName) { string url = m_FilePath + fileName; if (!File.Exists(url)) return; string jsonData = ReadData(url); Debug.Log($"{fileName}"); JsonData js = JsonMapper.ToObject(jsonData); //将json集合转换list ...
Unity 读取Json常用的两种方式 使用的是Litjson 1、读取本地Json publicvoidReadJson() { StreamReader streamReader=newStreamReader(Application.dataPath +"/XXX.json");stringstr =streamReader.ReadToEnd(); json=JsonMapper.ToObject(str); } 2、请求http(强烈建议先下载到本地再读取)...
{ //获取到路径 string fileUrl = @"c:\Temp\jsonInfo.txt"; //读取文件 StreamReader str = File.OpenText(fileUrl); //string类型的数据常量 //数据保存 string readData = str.ReadToEnd(); str.Close(); //返回数据 return readData; } //解析Json数据 public void ParseData(string jsonData) {...
这里用到JSON.serialized方法,其目的是将JSON数据序列化,进而使用Encoding.UTF8的方式保存数据。保存的格式可以是txt或者json。 读取JSON文件 首先添加获取本地文件的方法,因为之前我将文件保存在Resources文件夹下,因此获取地址也是写死的(不建议)。 voidLoadJsonFromFile(refJSONjson){TextAssettxt=Resources.Load("_av...