如何从Android的Unity StreamingAssets中读取JSON [英] How read json from Unity StreamingAssets, Android
本文介绍了如何从Android的Unity StreamingAssets中读取JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从Android应用程序的StreamingAssets中读取json?
How read json from StreamingAssets for android app?
对于iOS,我阅读了此代码,
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<Main> (json);
bundleForPing = itemsContent.bundleID;
}
但是如何阅读android ...请帮助
but how read for android ... please help
推荐答案
基于此手册:
在Android上,文件包含在压缩的.jar文件中(该文件与标准zip压缩文件的格式基本相同).这意味着,如果您不使用Unity的WWW类来检索文件,则需要使用其他软件来查看.jar存档中的内容并获取文件.
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<Main> (json);
bundleForPing = itemsContent.bundleID;
}
这篇关于如何从Android的Unity StreamingAssets中读取JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文