[Unity] JsonUtility

Unity 2023. 6. 9. 11:42
728x90

ToJson -> JSON 형식으로 객체를 변환 한다

FromJson -> 객체를 JSON으로 표현한다

[System.Serializable]
public class PlayerInfo
{
    public string name;
    public int lives;
    public float health;
    
    public static PlayerInfo CreateFromJSON(string jsonString)
    {
    	return JsonUtility.FromJson<PlayerInfo>(jsonString);
    }
    public string SaveToString()
    {
    	return JsonUtility.ToJson(this);
    }
}
728x90
Posted by 바르마스
,