Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load JSON file in Android
public JSONObject loadJSON(Context cxt, String file) {
JSONObject json = null;
try {
InputStream is = cxt.getAssets().open(file);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String data = new String(buffer, "UTF-8");
json = new JSONObject(data);
} catch (Exception ex) {
ex.printStackTrace();
}
return json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.