废话不说了,直接上代码:
//读取StreamingAssets中的配置文件复制到移动端的Application.persistentDataPath路径下
private IEnumerator GetJsonFiles(){
string path = Application.streamingAssetsPath + "/Configs/CpuInfo.json";
UnityWebRequest uwr = new UnityWebRequest(path);
yield return uwr.SendWebRequest();
string newPath = Application.persistentDataPath + "/" + "CpuInfo.json";
File.WriteAllBytes(newPath, www.downloadHandler.data);
}
读取之后,我们就可以获取android手机中的配置文件,并将它读取出来。注意Android端不能用File类的语法,运行不了的。
public void ReadJson(){
string path = Application.persistentDataPath + "/CpuInfo.json";
StreamReader json = new StreamReader(path);
string input = json.ReadToEnd();
//我这里使用的是LitJson解析的Json配置表
Dictionary<string, List<Dictionary<string, object>>&g