teja2495
12/9/2018 - 7:30 PM

Read from Local JSON file

Put the JSON file under assets folder which is under the App folder of the project.

public String loadJSONFromAsset() {
        String json = null;
        try {
            InputStream is = MapsActivity.this.getAssets().open("trip.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        return json;
}