implementation "com.squareup.moshi:moshi-kotlin:1.12.0" kotlin data class User(val id: Int, val name: String, val email: String) kotlin val moshi = Moshi.Builder() .addLast(KotlinJsonAdapterFactory()) .build() kotlin val client = OkHttpClient() val request = Request.Builder() .url("https://api.example.com/users") .build() val response = client.newCall(request).execute() val responseBody = response.body?.string() val adapter: JsonAdapter<User> = moshi.adapter(User::class.java) val user = adapter.fromJson(responseBody)


上一篇:
下一篇:
切换中文