None 个参数可以使用 Gson 提供的参数调用

None of the arguments can be called with the agruments supplied with Gson

我已经开始使用 Kotlin Multiplatform 库,并且在 android 端使用 Gson 来做一些处理。因为我知道 iOS 不支持 Gson,所以我决定创建一个名为 convertToJsonexpected 函数,它具有 return 类型的 class。但是,当我执行 actual 时,出现以下错误:

None of the arguments can be called with the arguments supplied

这发生在这行代码中:

actual fun convertFromJson(json:String): ClassName {
    return Gson().fromJson(json, ClassName::class) // this is where the error lies
}

我还有一个名为 convertToJson 的函数的 actual 实现,它不会给我一个错误,所以我想知道为什么上面提到的 convertFromJson 函数给我一个错误.

我们将不胜感激任何帮助或建议。

Gson 在 java 中实现,其 fromJson 接受 java.lang.Class 的实例作为参数,因此您应该将 ClassName::class 替换为 ClassName::class.java,因为前者为您提供了 kotlin.reflect.KClass.

的实例