I have a JSON loop and I am able to get objects in the loop, but the problem is my output is not in order:

My expected output is: 

`Menu Id 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23` 

but I get results like:

`Menu Id: 19,18,23,16,17,14,15,12,13,21,20,22,4,3,11,2,1`. 

How can I sort this the way I expect?

```
           JSONArray values = menuObject.toJSONArray(names);
           for (int i = 0; i< values.length(); i++) {
                        JSONObject json2 = (JSONObject) values.getJSONObject(i);
                        //int menu_id = json2.getInt("menu_id");
                        menu_id = json2.getString("menu_id");
                        int m_id = Integer.parseInt(menu_id);
                        if (json2.has("menu_parent")) {
                           menu_parent = json2.getString("menu_parent");    
                        }
            if (m_id < 0) {

               //
             } else {
               id = id + menu_id + ",";
               int menu_category = Integer.parseInt(menu_parent);
               System.out.println("Menu Id" + id);
                   if (json2.has("menu_name")) {
                     menu_list = json2.getString(KEY_MENU).trim();
                     System.out.println("Menu List" +menu_title);
                     menu_title = menu_title + menu_list + ",";
                   }
               }

           }

```