android - Ktor 客户端的 JsonFeature 未解决

标签 android json kotlin ktor

我正在 android 中启动基于 Ktor 的客户端,我想使用任何序列化程序,目前,来自 kotlinx 的序列化程序,但其他序列化程序的结果是相同的 - 未找到 JsonFeature(在下面的 fragment 中突出显示)。我错过了什么?

class StreamClient {
    val client: HttpClient
    init {
        client = HttpClient(Android) {
            install(JsonFeature) {
                serializer = KotlinxSerializer()
            }
        }
    }
}
Gradle :
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-android:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0")

最佳答案

这与您的问题完全无关,但由于 Ktor 2.0 JsonFeature已弃用,取而代之的是 ContentNegotation

install(ContentNegotiation) {
    json()
}
https://ktor.io/docs/eap/serialization-client.html#install_plugin

关于android - Ktor 客户端的 JsonFeature 未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65952200/

相关文章:

json - 如何通过 LimeSurvey 的远程控制 (JSON) 更新响应

android - 导航组件 : NavHostFragment inside a fragment

android - Firebase Crashlytics 使用 Retrofit 和协程报告 Android 项目上的假崩溃

android - 如何在 Android 中使用 ImageView 显示图像

java - 'java.util.ArrayList' 未经检查的分配

java - Android 中 R.java 中的语法错误

android - 如何在许多不同的设备上测试我的相机应用程序

arrays - bash 将数组拆分为具有动态名称的单独文件

json - 如何使用 jq 从 JSON 中提取变量键及其值?

Kotlin 类型安全的类型别名