João Oliveira
João Oliveira

Reputation: 1

Save json files in android

I have my files saved on resources folder and when I try to write other thing it does not work. Could anyone help me?

public void SaveGameData()
{
    PlayerSavedData aux = new PlayerSavedData();
    aux.allSavedPlayerData = SavePlayerInformation.playerDataList.ToArray<PlayerData> ();

    string dataAsJson = JsonUtility.ToJson (aux);

    string filePath = Application.persistentDataPath + "playerInformation.json";
    File.WriteAllText (filePath, dataAsJson);

}

Upvotes: 0

Views: 1391

Answers (2)

zambari
zambari

Reputation: 5035

This is wrong

string filePath = Application.persistentDataPath + "playerInformation.json";

Try this instead

string filePath = Path.Combine(Application.persistentDataPath,"playerInformation.json");

Also note that you need WRITE_EXTERNAL_STORAGE permission

Upvotes: 1

Trung Bui
Trung Bui

Reputation: 111

The Resoures folder simply doens't exist any more afer your build. The assets in the Resources folder get packed into the game's archive for assets. Better you put file in StreamingAssets folder.

Upvotes: 0

Related Questions