public static JSONObject loadJsonFromAsset(Context context, String fileName) { JSONObject jsonObject = null; AssetManager manager = context.getAssets(); try (InputStream is = manager.open(fileName)) { int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); String json = new String(buffer, "UTF-8"); jsonObject = new JSONObject(json); } catch (IOException | JSONException e) { e.printStackTrace(); Log.e(TAG,e.toString()); } return jsonObject; }
从assets读取json文件
最新推荐文章于 2024-09-20 15:32:13 发布