系统自带的 JSONObject 简化操作, 屏蔽了异常的抛出
函数 | 案例 | 结果 |
---|---|---|
toJSONObject(): JSONObject? | val jsonObject: JSONObject? = “{}”.toJSONObject() | |
toJSONArray(): JSONArray? | val jsonArray: JSONArray? = “{}”.toJSONArray() | |
toJSONObject(name: String): JSONObject? | val jsonObject: toJSONObject? = jsonObject?.toJSONObject(“b”) | |
toJSONArray(name: String): JSONArray? | val jsonArray: toJSONArray? = jsonObject?.toJSONArray(“b”) | |
getIntValue(name: String): Int? | val b: Boolean? = jsonObject?.getIntValue(“b”) | |
getLongValue(name: String): Long? | val b: Boolean? = jsonObject?.getLongValue(“b”) | |
getBooleanValue(name: String): Boolean? | val b: Boolean? = jsonObject?.getBooleanValue(“b”) | |
getDoubleValue(name: String): Double? | val b: Boolean? = jsonObject?.getDoubleValue(“b”) | |
getStringValue(name: String): String? | val b: Boolean? = jsonObject?.getStringValue(“b”) | |
isEmpty(): Boolean | val empty: Boolean = jsonArray?.isEmpty() | |
isNotEmpty(): Boolean | val notEmpty: Boolean = jsonArray?.isNotEmpty() | |
size(): Int | val size: Int = jsonArray?.size() |