[Solved] Android: Access all nested JSON objects dynamically [duplicate]


Thank you DroiDev and MohamedMohaideenAH. Finally i got the solution

private void parseJson(JSONObject jsonObject){

    try {

        for(int i = 0; i < jsonObject.length(); i++){


            if(jsonObject.get(jsonObject.names().getString(i)) instanceof JSONObject){

                Log.e("===Start===", "===Start===");

                Log.e("objectName", jsonObject.names().getString(i));

                JSONObject  singleObj = new JSONObject(jsonObject.get(jsonObject.names().getString(i)).toString());

                Iterator<String> keys= singleObj.keys();
                while (keys.hasNext()){
                    String keyValue = keys.next();
                    String valueString = singleObj.getString(keyValue);

                    if(!isJSONObjectOrString(valueString))
                        Log.e(keyValue, valueString);
                }

                Log.e("===End===", "===End===");

                parseJson(singleObj);
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

}

private boolean isJSONObjectOrString(String str) {
    try {
        new JSONObject(str);
    } catch (JSONException e) {
        //e.printStackTrace(); //If you uncomment, log will confuse you
        return false;//If string
    }
    return true;//If JSONObject
}

solved Android: Access all nested JSON objects dynamically [duplicate]