Skip to content

Instantly share code, notes, and snippets.

@janishar
Created October 10, 2016 10:52
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 janishar/4d1b3a46bab60d54c87f2d574c1fc641 to your computer and use it in GitHub Desktop.
Save janishar/4d1b3a46bab60d54c87f2d574c1fc641 to your computer and use it in GitHub Desktop.
public class Utils {
private static final String TAG = "Utils";
public static List<InfiniteFeedInfo> loadInfiniteFeeds(Context context){
try{
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
JSONArray array = new JSONArray(loadJSONFromAsset(context, "infinite_news.json"));
List<InfiniteFeedInfo> feedList = new ArrayList<>();
for(int i=0;i<array.length();i++){
InfiniteFeedInfo feed = gson.fromJson(array.getString(i), InfiniteFeedInfo.class);
feedList.add(feed);
}
return feedList;
}catch (Exception e){
Log.d(TAG,"seedGames parseException " + e);
e.printStackTrace();
return null;
}
}
private static String loadJSONFromAsset(Context context, String jsonFileName) {
String json = null;
InputStream is=null;
try {
AssetManager manager = context.getAssets();
Log.d(TAG,"path "+jsonFileName);
is = manager.open(jsonFileName);
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment