Created
July 22, 2020 13:56
-
-
Save necatisozer/91b4f56ed570b95ad28464f3b5555b48 to your computer and use it in GitHub Desktop.
This file contains 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
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