fromJson和toJson用于Moshi的通用Any对象

时间:2020-11-06 06:27:40

标签: gson moshi

我正在从Gson迁移到Moshi,我想将这些“ Gson函数”转换为“ Moshi代码”:

inline fun <reified T : Any> String.toList(): List<T> =
    Gson().fromJson(this, Array<T>::class.java).asList()
fun Any.toJSONArray(): JSONArray {
    return JSONArray(Gson().toJson(this, Any::class.java))
}

有什么建议吗?

0 个答案:

没有答案