public static HashMap < String , JSONObject > flatRessources ( JSONObject object ) throws JSONException { HashMap < String , JSONObject > result = new HashMap < String , JSONObject > ( ) ; // no cycle in hierarchies!! if ( object . has ( "resourceId" ) && object . has ( "childShapes" ) ) { result . put ( object . getString ( "resourceId" ) , object ) ; JSONArray childShapes = object . getJSONArray ( "childShapes" ) ; for ( int i = 0 ; i < childShapes . length ( ) ; i ++ ) { result . putAll ( flatRessources ( childShapes . getJSONObject ( i ) ) ) ; } } ; return result ; }
Prepare a model JSON for analyze resolves the hierarchical structure creates a HashMap which contains all resourceIds as keys and for each key the JSONObject all id are keys of this map