using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class ReadJosn
{
///
/// 通过文件解析json
///
///
///
public static JsonExample LoadJsonFromFile(string fileName)
{
if (Application.platform == RuntimePlatform.WindowsEditor
|| Application.platform == RuntimePlatform.WindowsPlayer)
{
if (!File.Exists(Application.dataPath + "/StreamingAssets/Setting/" + fileName))
{
return null;
}
StreamReader sr = new StreamReader(Application.dataPath + "/StreamingAssets/Setting/" + fileName);
if (sr == null)
{
return null;
}
string json = sr.ReadToEnd();
if (json.Length > 0)
{
return JsonUtility.FromJson(json);
}
return null;
}
//if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
//{
// if (!File.Exists(Application.dataPath + "/storage/emulated/0/Android/data/com.zwn.VirusEnd2/files/Setting/" + fileName))
// {
// return null;
// }
// StreamReader sr = new StreamReader(Application.dataPath + "/storage/emulated/0/Android/data/com.zwn.VirusEnd2/files/Setting/" + fileName);
// if (sr == null)
// {
// return null;
// }
// string json = sr.ReadToEnd();
// if (json.Length > 0)
// {
// return JsonUtility.FromJson(json);
// }
// return null;
//}
return null;
}
public static T LoadJson(string json)
{
T jsonExample = JsonUtility.FromJson(json);
return jsonExample;
}
}