- Home /
Question by
LordaBG · Jan 03, 2019 at 03:34 PM ·
c#androidscripting problemjsondatabase handling
Saving JSON file in Android,How to save json file in android
I want to save a json file in android. I prepare a json sample file, which I save in the streamingAssetsFolder and ship it with my game. Then on the first launch of the game I want to get the json sample file from the streamingAssetsFolder and save it to DataPersistentPath. I have read that I can not save json file in the streamingAssetsFolder when Im on android, so this is why I want to use the DataPersistentPath to store and update my json database. The reading from the streamingAssetsFolder works fine, but it doesn't save it to the DataPersistentPath.
public static LData ReadJson(string path)
{
WWW www = new WWW(path);
while (!www.isDone) { }
string json = www.text;
return JsonUtility.FromJson<LData>(json);
}
public static void SaveToJson(LData ldb, string path)
{
string dataAsJson = JsonUtility.ToJson(ldb, true); //true=pretty
File.WriteAllText(path, dataAsJson);
print("Data Saved to Json");
}
These are my read and write json methods.
Note: Everything works perfect in the PC build!
Comment