Save String
This saves a string as a JSON file, encrypting it with the provided key.
Copy string text = "Hello, World!";
string path = Application.persistentDataPath;
string fileName = "exampleString";
JsonExtensions.SaveString(text, path, fileName, "encryptionKey");
Load String
This loads a JSON file, decrypts its content, and converts it back to a string.
Copy string path = Application.persistentDataPath;
string fileName = "exampleString";
string getText = JsonExtensions.LoadString(fileName, path, "encryptionKey");
Save Object
This saves an object (like player data) to a JSON file and encrypts it.
Copy [System.Serializable]
public class PlayerData
{
public string Name;
public int Score;
}
PlayerData player = new PlayerData {
Name = "Alice",
Score = 100
};
string path = Application.persistentDataPath;
string fileName = "playerData";
JsonExtensions.SaveObject(player, path, fileName, "encryptionKey");
Load Object
This loads and decrypts a JSON file, converting it back into an object.
Copy string path = Application.persistentDataPath;
string fileName = "playerData";
PlayerData savedPlayer =
JsonExtensions.LoadObject<PlayerData>(fileName, path, "encryptionKey");
Save List
This saves a list of integers to a JSON file with EncryptExtensions.
Copy List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
string path = Application.persistentDataPath;
string fileName = "numberList";
JsonExtensions.SaveListJson(numbers, path, fileName, "encryptionKey");
Load List
This loads a JSON file, decrypts it, and converts it back into a list.
Copy string path = Application.persistentDataPath;
string fileName = "numberList";
List<int> savedNumbers = JsonExtensions.LoadListJson<int>(fileName, path, "encryptionKey");
Save Dictionary
This saves a dictionary of player scores to a JSON file with EncryptExtensions.
Copy Dictionary<string, int> playerScores = new Dictionary<string, int>
{
{ "Alice", 100 },
{ "Bob", 80 },
{ "Charlie", 60 }
};
string path = Application.persistentDataPath;
string fileName = "playerScores";
JsonExtensions.SaveDictionaryJson(playerScores, path, fileName, "encryptionKey");
Load Dictionary
This loads and decrypts a JSON file, converting it back into a dictionary.
Copy string path = Application.persistentDataPath;
string fileName = "playerScores";
Dictionary<string, int> getScores = JsonExtensions.LoadDictionaryJson<string,int>(fileName, path, "encryptionKey");
foreach (var score in getScores)
{
Debug.Log($"{score.Key}: {score.Value}");
}