Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. public static Vector<String> objRecursive(Vector<String> jsonObj, Vector<String> sortie, Vector<String> racine) {
  2.         Vector<String> returnObj = new Vector<>();
  3.         returnObj.addElement("{}");
  4.         Vector<String> returnRacine = racine;
  5.        
  6.         int isEmpty = 0;
  7.         for(int z = 0; z<jsonObj.size() ; z++)
  8.         {
  9.        
  10.             JSONObject jsonObject = new JSONObject(jsonObj.elementAt(z));
  11.             System.out.println(racine);
  12.             JSONArray test;
  13.            
  14.             Vector<String> keys=new Vector<>();
  15.             for (String name : jsonObject.keySet()) {  
  16.                 keys.addElement(name);
  17.             }
  18.             String pathRacine = racine.get(z);
  19.             if(keys.size() == 0) {
  20.                 isEmpty++;
  21.             }
  22.             for(int i = 0; i<keys.size() ; i++) {
  23.                
  24.                 if(jsonObject.get(keys.elementAt(i).toString()) instanceof String)
  25.                 {
  26.                     pathRacine += keys.elementAt(i).toString() + "/";
  27.                     sortie.addElement(pathRacine + jsonObject.get(keys.elementAt(i).toString()) + "(string)");
  28.                     //TODO
  29.                 }
  30.                 else if(jsonObject.get(keys.elementAt(i).toString()) instanceof Integer) {
  31.                     pathRacine += keys.elementAt(i).toString() + "/";
  32.                     sortie.addElement(pathRacine + jsonObject.get(keys.elementAt(i).toString()) + "(int)");
  33.                     //TODO
  34.                 }
  35.                
  36.                 else if(jsonObject.get(keys.elementAt(i).toString()) instanceof Boolean) {
  37.                     pathRacine += keys.elementAt(i).toString() + "/";
  38.                     sortie.addElement(pathRacine + jsonObject.get(keys.elementAt(i).toString()) + "(bool)");
  39.                     //TODO
  40.                 }
  41.                
  42.                 else if(jsonObject.get(keys.elementAt(i).toString()) instanceof Double) {
  43.                     pathRacine += keys.elementAt(i).toString() + "/";
  44.                     sortie.addElement(pathRacine + jsonObject.get(keys.elementAt(i).toString()) + "(double)");
  45.                     //TODO
  46.                 }
  47.                
  48.                 else if(jsonObject.get(keys.elementAt(i).toString()) instanceof JSONArray) {
  49.                     test = (JSONArray)jsonObject.get(keys.elementAt(i).toString());
  50.                     pathRacine += keys.elementAt(i).toString() + "/";
  51.                     for(int y = 0; y<test.length() ; y++) {
  52.                         sortie.addElement(pathRacine + test.get(y) + "(array)");
  53.                     }
  54.                 }
  55.                 else if(jsonObject.get(keys.elementAt(i).toString()) instanceof JSONObject) {
  56.                     returnObj.addElement(jsonObject.get(keys.elementAt(i).toString()).toString());
  57.                     returnRacine.addElement(pathRacine + keys.elementAt(i).toString());
  58.                 }
  59.                
  60.             }
  61.         }
  62.         if(isEmpty == jsonObj.size()) {
  63.             return sortie;
  64.         }
  65.        
  66.         return objRecursive(returnObj, sortie, returnRacine);
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement