Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Utility {
- public static String getFileContent(Context context) throws IOException {
- InputStream inputStream = context.getAssets().open("json/dannye.json");
- StringBuilder rawContentBuilder = new StringBuilder();
- byte[] buffer = new byte[1024];
- inputStream.read(buffer);
- do {
- String chunk = new String(buffer);
- rawContentBuilder.append(chunk);
- } while (inputStream.read(buffer) > 0);
- return rawContentBuilder.toString();
- }
- }
- private List<Dannye> initData() {
- try {
- String rawJson = Utility.getFileContent(getContext());
- JSONObject(rawJson).getJSONArray(groupName);
- JSONArray group = new JSONObject(rawJson).getJSONArray("d_1_18");
- Log.e(TAG, "initializeHeroes: " + group);
- list = new ArrayList<>();
- for (int i = 0; i < group.length(); i++) {
- JSONObject hero = group.getJSONObject(i);
- String hour = hero.getString("hour");
- String lesson = hero.getString("lesson");
- String spes = hero.getString("spes");
- String aut = hero.getString("aut");
- Dannye dannye = new Dannye(hour, lesson, spes, aut);
- list.add(dannye);
- }
- } catch (IOException e) {
- System.out.println("NO bATTLE.JSON!!!");
- } catch (JSONException e) {
- System.out.println("JSON MALFoRMEEEED!!");
- }
- return list;
- }
Add Comment
Please, Sign In to add comment