Created
June 19, 2014 13:03
-
-
Save anonymous/89f8163fb22f77f4f9d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Map<String, Object> getV3Map(JSONObject v3JsonObject) throws JSONException{ | |
Map<String, Object> mapV3 = new HashMap<String, Object>(); | |
List<Object> mapV3Arr = null; | |
Iterator<?> keys = v3JsonObject.keys(); | |
while(keys.hasNext() ){ | |
String key = (String)keys.next(); | |
if(v3JsonObject.get(key) instanceof JSONObject){ | |
mapV3.put(key, getV3Map((JSONObject)v3JsonObject.get(key))); | |
} else if(v3JsonObject.get(key) instanceof JSONArray) { | |
mapV3Arr = new ArrayList<Object>(); | |
JSONArray jArray = (JSONArray)v3JsonObject.get(key); | |
for(int i = 0; i < jArray.length(); i++) { | |
if(jArray.get(i) instanceof JSONObject || jArray.get(i) instanceof JSONArray){ | |
mapV3Arr.add(getV3Map((JSONObject)jArray.get(i))); | |
} else { | |
mapV3Arr.add(jArray.get(i)); | |
} | |
} | |
mapV3.put(key, mapV3Arr); | |
} else { | |
mapV3.put(key, v3JsonObject.get(key)); | |
} | |
} | |
return mapV3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment