Last active
February 25, 2017 11:45
-
-
Save ashmeh6/fbff0aabfb16a407a497156b282783ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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