I have a json response which is dynamic such that even the key name and index no.can change
{
"Assigned": {
    "DC": 7,
    "EmpCode": "E0104",
    "FS": 8
}
}
I want to convert it into JsonArray and fetch all the key names and values dynamically under the object 'Assigned'.But I am only getting the value name by trying this.
try {
                        //converting dynamic jsonobject to json array and fetching value as well as key name
                        JSONObject jsonObject = response.getJSONObject("Assigned");
                        Iterator x = jsonObject.keys();
                        JSONArray jsonArray = new JSONArray();
                        while (x.hasNext()) {
                            String key = (String) x.next();
                            jsonArray.put(jsonObject.get(key));
                    }
                        Toast.makeText(RolesActivity.this,jsonArray.toString(), Toast.LENGTH_LONG).show();
                        Log.d("jsonarray",jsonArray.toString());
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        Toast.makeText(RolesActivity.this, e.toString(), Toast.LENGTH_SHORT).show();
                    }
 
     
    