Skip to content

Instantly share code, notes, and snippets.

Created June 19, 2014 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/89f8163fb22f77f4f9d3 to your computer and use it in GitHub Desktop.
Save anonymous/89f8163fb22f77f4f9d3 to your computer and use it in GitHub Desktop.
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