Eri*_*ass 30
你应该把文件无论是在/assets
或/res/raw
你的Android项目的目录.从那里,您可以使用以下任一方式检索它:Context.getResources().openRawResource(R.raw.filename)
或Context.getResources().getAssets().open("filename")
.
LOG*_*TAG 10
把json文件放在assets文件夹中,我已经像这样使用了这个方法
public static String jsonToStringFromAssetFolder(String fileName,Context context) throws IOException {
AssetManager manager = context.getAssets();
InputStream file = manager.open(fileName);
byte[] data = new byte[file.available()];
file.read(data);
file.close();
return new String(data);
}
Run Code Online (Sandbox Code Playgroud)
在解析时我们可以使用如下方法:
String jsondata= jsonToStringFromAssetFolder(your_filename, your_context);
jsonFileToJavaObjectsParsing(jsondata); // json data to java objects implementation
Run Code Online (Sandbox Code Playgroud)
更多信息:Prativa的博客
归档时间: |
|
查看次数: |
14280 次 |
最近记录: |