Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public static List<List<List<Integer>>> JsonToInt()
  2. {
  3. //array, array, array int
  4. String fileLocation = "/Users/amy/Documents/DagsMario/DagstuhlGAN/example.json";
  5. List<String> lines = new ArrayList();
  6. try
  7. {
  8. lines = Files.readAllLines(Paths.get(fileLocation), Charset.defaultCharset());
  9. }
  10. catch (IOException e1)
  11. {
  12. e1.printStackTrace();
  13. }
  14.  
  15. String myJSONString="";
  16. for(String s: lines)
  17. myJSONString+=s;
  18. JsonArray jarray1 = new Gson().fromJson(myJSONString, JsonArray.class);//first array
  19.  
  20. List<List<List<Integer>>> myReturnList = new ArrayList();
  21.  
  22. for(int i = 0; i < jarray1.size();i++)
  23. {
  24. List<List<Integer>> myFirstSubList = new ArrayList();
  25. JsonArray jarrayi = ((JsonArray)jarray1.get(i));
  26. for(int j = 0; j < jarrayi.size();j++)
  27. {
  28. List<Integer> mySecondSubList = new ArrayList();
  29. JsonArray jarrayj = ((JsonArray)jarrayi.get(j));
  30. for(JsonElement je: jarrayj)
  31. {
  32. mySecondSubList.add(je.getAsInt());
  33. }
  34. myFirstSubList.add(mySecondSubList);
  35. }
  36. myReturnList.add(myFirstSubList);
  37. }
  38. return myReturnList;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement