Using JSON File in Android App Resources

前端 未结 8 1196
盖世英雄少女心
盖世英雄少女心 2020-11-28 21:00

Suppose I have a file with JSON contents in the raw resources folder in my app. How can I read this into the app, so that I can parse the JSON?

8条回答
  •  日久生厌
    2020-11-28 21:15

    InputStream is = mContext.getResources().openRawResource(R.raw.json_regions);
                                int size = is.available();
                                byte[] buffer = new byte[size];
                                is.read(buffer);
                                is.close();
                               String json = new String(buffer, "UTF-8");
    

提交回复
热议问题