Guest User

Untitled

a guest
Oct 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class Utility {
  2.  
  3.  
  4. public static String getFileContent(Context context) throws IOException {
  5.  
  6. InputStream inputStream = context.getAssets().open("json/dannye.json");
  7.  
  8. StringBuilder rawContentBuilder = new StringBuilder();
  9.  
  10. byte[] buffer = new byte[1024];
  11. inputStream.read(buffer);
  12.  
  13. do {
  14. String chunk = new String(buffer);
  15. rawContentBuilder.append(chunk);
  16. } while (inputStream.read(buffer) > 0);
  17.  
  18. return rawContentBuilder.toString();
  19. }
  20. }
  21.  
  22. private List<Dannye> initData() {
  23.  
  24.  
  25. try {
  26.  
  27. String rawJson = Utility.getFileContent(getContext());
  28. JSONObject(rawJson).getJSONArray(groupName);
  29. JSONArray group = new JSONObject(rawJson).getJSONArray("d_1_18");
  30.  
  31. Log.e(TAG, "initializeHeroes: " + group);
  32.  
  33. list = new ArrayList<>();
  34.  
  35. for (int i = 0; i < group.length(); i++) {
  36.  
  37. JSONObject hero = group.getJSONObject(i);
  38.  
  39.  
  40. String hour = hero.getString("hour");
  41. String lesson = hero.getString("lesson");
  42. String spes = hero.getString("spes");
  43. String aut = hero.getString("aut");
  44.  
  45. Dannye dannye = new Dannye(hour, lesson, spes, aut);
  46. list.add(dannye);
  47. }
  48.  
  49. } catch (IOException e) {
  50. System.out.println("NO bATTLE.JSON!!!");
  51. } catch (JSONException e) {
  52. System.out.println("JSON MALFoRMEEEED!!");
  53. }
  54.  
  55. return list;
  56.  
  57. }
Add Comment
Please, Sign In to add comment