using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
[System.Serializable]
public class Data
{
public int m_nLevel;
}
public class JsonTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
// file save
Data data3 = new Data();
data3.m_nLevel = 99;
File.WriteAllText(Application.dataPath + "/TestJson.json", JsonUtility.ToJson(data3));
// file load
string str2 = File.ReadAllText(Application.dataPath + "/TestJson.json");
Data data4 = JsonUtility.FromJson<Data>(str2);
}
// Update is called once per frame
void Update()
{
}
}
이게 TestJson.json파일을 만들고 거기에 m_nLevel을 저장한뒤, TestJson.json파일의 데이터를 받아오는 거잖아요?
근데 저는 fileLoad로 데이터를 받아온 뒤, m_nLevel을 변경하고 filesave로 저장하고 싶어요...
근데그러면 TestJson.json파일이 아직 안 만들어진 상태라서 오류가 뜨는거 같은데 어떻게 할까요?ㅠㅠ
저는
if (!File.Exists("/TestJson.json"))
File.Create("/TestJson.json");
이걸로 추가하려 했는데 그래도 오류 나더라구요
string path = Application.dataPath + "/Save/save" + saveNum + ".sav"; if(File.Exists(path)) { string str = File.ReadAllText(path); data3.AddRange(JsonUtility.FromJson(str)); }
아까꺼 변수명 수정안해서 적어서 다시 올렸다