Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<List<List<Integer>>> JsonToInt()
- {
- //array, array, array int
- String fileLocation = "/Users/amy/Documents/DagsMario/DagstuhlGAN/example.json";
- List<String> lines = new ArrayList();
- try
- {
- lines = Files.readAllLines(Paths.get(fileLocation), Charset.defaultCharset());
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
- String myJSONString="";
- for(String s: lines)
- myJSONString+=s;
- JsonArray jarray1 = new Gson().fromJson(myJSONString, JsonArray.class);//first array
- List<List<List<Integer>>> myReturnList = new ArrayList();
- for(int i = 0; i < jarray1.size();i++)
- {
- List<List<Integer>> myFirstSubList = new ArrayList();
- JsonArray jarrayi = ((JsonArray)jarray1.get(i));
- for(int j = 0; j < jarrayi.size();j++)
- {
- List<Integer> mySecondSubList = new ArrayList();
- JsonArray jarrayj = ((JsonArray)jarrayi.get(j));
- for(JsonElement je: jarrayj)
- {
- mySecondSubList.add(je.getAsInt());
- }
- myFirstSubList.add(mySecondSubList);
- }
- myReturnList.add(myFirstSubList);
- }
- return myReturnList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement