Gson fromJson和toJson用于具有Moshi的任何通用对象

Gson fromJson和toJson用于具有Moshi的任何通用对象,gson,moshi,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().toJs

我正在从
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))
}