Yes, it's possible. You can put the json file in the assets folder and use the getAssets().open() method to read the json file, convert it to string, and convert it to JSONObject.
It will be a simple code like below.
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAsset().open("file name.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;
}
JSONObject obj = new JSONObject(json_return_by_the_function);
//Pars JSONObject and draw it on the list as you want.
© 2024 OneMinuteCode. All rights reserved.