Skip to content

Instantly share code, notes, and snippets.

@fbukevin
Created December 28, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbukevin/8b47f5f867cc87bb980fab740f61df48 to your computer and use it in GitHub Desktop.
Save fbukevin/8b47f5f867cc87bb980fab740f61df48 to your computer and use it in GitHub Desktop.
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