unity json 存档备忘
public class Save
{
public string name;
public int age;
public int[] array;
}
void Start()
{
Save save = SetSaveData();
string filePath = Application.dataPath + "/SaveFile/save.json";
string strJson = JsonMapper.ToJson(save);
StreamWriter sw = new StreamWriter(filePath);
sw.Write(strJson);
sw.Close();
LoadSave();
}
private void LoadSave()
{
string filePath = Application.dataPath + "/SaveFile/save.json";
if(File.Exists(filePath))
{
StreamReader sr = new StreamReader(filePath);
string strJson = sr.ReadToEnd();
sr.Close();
Save save = JsonMapper.ToObject<Save>(strJson);
print(save.age);
print(save.array[0]);
}else
{
print("save file lost");
}
}