Hi I'm trying to sort a JSONArray of JSONObjects alphabetically but it seems to add in backslashes as it turns it into one big string. Does anyone know how to do arrange a JSONArray of JSONObjects Alphabetically?
I have tried converting the JSONArray to arraylist but it becomes an JSONArray of Strings that are in alphabetical order rather than JSONObjects
public static JSONArray sortJSONArrayAlphabetically(JSONArray jArray) throws JSONException{
ArrayList<String> arrayForSorting = new ArrayList<String>();
if (jArray != null) {
for (int i=0;i<jArray.length();i++){
//FIND OUT COUNT OF JARRAY
arrayForSorting.add(jArray.get(i).toString());
}
Collections.sort(arrayForSorting);
jArray = new JSONArray(arrayForSorting);
}
return jArray;
}