Skip to content

Instantly share code, notes, and snippets.

@necatisozer
Created July 22, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save necatisozer/91b4f56ed570b95ad28464f3b5555b48 to your computer and use it in GitHub Desktop.
Save necatisozer/91b4f56ed570b95ad28464f3b5555b48 to your computer and use it in GitHub Desktop.
import org.json.JSONException
import org.json.JSONObject
@Throws(JSONException::class)
fun jsonOf(vararg pairs: Pair<String, Any?>) = JSONObject().apply {
for ((key, value) in pairs) {
when (value) {
is Boolean -> put(key, value)
is Double -> put(key, value)
is Int -> put(key, value)
is Long -> put(key, value)
else -> put(key, value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment