Created
November 30, 2020 15:43
-
-
Save ArnyminerZ/6aca0630a96f5559d3b9b797c9b48f3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun JSONArray.sort(keyName: String): JSONArray { | |
val sortedJsonArray = JSONArray() | |
val jsonValues = arrayListOf<JSONObject>() | |
for (a in 0 until length()) | |
jsonValues.add(getJSONObject(a)) | |
jsonValues.sortWith { a, b -> | |
val valA = a.getStringSafe(keyName) ?: a.get(keyName) as String | |
val valB = b.getStringSafe(keyName) ?: b.get(keyName) as String | |
valA.compareTo(valB, true) | |
} | |
for (k in 0 until length()) | |
sortedJsonArray.put(jsonValues[k]) | |
return sortedJsonArray | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment