Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
fun JSONArray.sort(keyName: String): JSONArray {
val sortedJsonArray = JSONArray()
val jsonValues = arrayListOf<JSONObject>()
for (a in 0 until length())
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())
return sortedJsonArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment