How read json from StreamingAssets for android app?
For iOS I read with this code,
public void ReadJson(){
string path = "/Raw/elements.json";
#if UNITY_EDITOR
path = "/StreamingAssets/elements.json";
#endif
string json = File.ReadAllText(Application.dataPath + path);
itemsContent = JsonUtility.FromJson (json);
bundleForPing = itemsContent.bundleID;
}
but how read for android ... please help
解决方案
Based on this Manual:
On Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity’s WWW class to retrieve the file, you need to use additional software to see inside the .jar archive and obtain the file.
public void ReadJson(){
string path = Application.streamingAssetsPath + "/elements.json";
#if UNITY_EDITOR
path = "/StreamingAssets/elements.json";
#endif
WWW www = new WWW(path);
while(!www.isDone) {}
string json = www.text;
itemsContent = JsonUtility.FromJson (json);
bundleForPing = itemsContent.bundleID;
}