我正在尝试初始化 Ktor http 客户端并设置 json 序列化。我需要允许JSON.nonstrict对象允许的非严格反序列化。只是无法了解如何将此设置应用于序列化程序。
val client = HttpClient {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个针对iOS和Android的kotlin-multiplatform项目。Ktor http客户端在通用模块中使用。
一切都适用于Android应用程序。但是当使用iOS lib构建项目时,我收到以下异常:
> Task :app:compileKotlinIos FAILED
src/commonMain/kotlin/com/ottamotta/mozoli/api/MozoliApiKtor.kt:4:8: error: unresolved reference: io
import io.ktor.client.HttpClient
^
src/commonMain/kotlin/com/ottamotta/mozoli/api/MozoliApiKtor.kt:5:8: error: unresolved reference: io
import io.ktor.client.features.feature
Run Code Online (Sandbox Code Playgroud)
...以及其他原因,说没有ktor依赖关系已解决。
这是build.gradle:
plugins {
id 'kotlin-multiplatform' version '1.3.10'
}
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
ext {
support_lib_version = '28.0.0'
ktor_version = '1.0.0'
}
def keystorePropertiesFile = rootProject.file("./app/secret.properties");
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.ottamotta.mozoli"
minSdkVersion …
Run Code Online (Sandbox Code Playgroud) 通过使用EventBus,我需要在Activity中发布一个事件(MyEvent)并在Android中的另一个Activity中接收该事件.我尝试了greenrobot EventBus性能测试项目,但无法做到这一点.
我在ActivitySubscriber中尝试过
MyEvent event = new MyEvent();
EventBus.getDefault().post(event);
Run Code Online (Sandbox Code Playgroud)
并试图在接收事件ActivityReceiver为
EventBus.getDefault().register(this);
public void onEvent(MyEvent event){
....
}
Run Code Online (Sandbox Code Playgroud)
但是我无法收到这个活动.任何人都可以让我知道我在哪里做错了吗?