Skip to content

Instantly share code, notes, and snippets.

@ashmeh6
Last active February 25, 2017 11:45
Show Gist options
  • Save ashmeh6/fbff0aabfb16a407a497156b282783ea to your computer and use it in GitHub Desktop.
Save ashmeh6/fbff0aabfb16a407a497156b282783ea to your computer and use it in GitHub Desktop.
//by ashish
//https://in.linkedin.com/in/ashishmehra610
public class ParseJsonFileAsync extends AsyncTask<Void, Void, String> {
Activity activity;
public ParseJsonFileAsync(Activity activity){
this.activity = activity;
}
@Override
protected String doInBackground(Void... params) {
String json = null;
try {
InputStream stream = activity.getAssets().open("my_json_file.json");//at assets folder
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
json = new String(buffer, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
return null;
}
return json;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
//parse
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment