通过改造调用添加多个@Path

Tak*_*aki 2 android kotlin retrofit

我有一个 api 请求,在 url 中我需要传递多个 @Path,我这样做了,但我不断收到错误,我想获得有关此问题的一些帮助,提前谢谢


  @Singleton
  @Provides
  fun provideRetrofitInstance(): ApiInterface {
      val httpLoggingInterceptor = HttpLoggingInterceptor()
      val interceptor = httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC)
      val okHttp = OkHttpClient.Builder()
              .addInterceptor(interceptor)
              .build()
      return Retrofit.Builder()
              .baseUrl("https://api.site.dev/api/v2/entries/")
              .addConverterFactory(GsonConverterFactory.create())
              .client(okHttp)
              .build()
              .create(ApiInterface::class.java)
  }

Run Code Online (Sandbox Code Playgroud)
  • 这是我的改造电话
 Error Unable to create call adapter for class com.dic.mydictionnary.models.DictionnaryModelItem
       for method ApiInterface.getDictionnaryWord
Run Code Online (Sandbox Code Playgroud)

*这是我的apiInterfac

@GET("{language_code}/{word}")
   fun getDictionnaryWord(
           @Path("language_code") language : String,
           @Path("word") word : String,
   ) : DictionnaryModelItem

}
Run Code Online (Sandbox Code Playgroud)

小智 5

看起来 Retrofit 正在尝试找到一种DictionnaryModelItem为您的服务接口创建的方法。您需要将其更改为:

   @GET("{language_code}/{word}")
   suspend fun getDictionnaryWord(
           @Path("language_code") language : String,
           @Path("word") word : String,
   ) : Response<DictionnaryModelItem>
Run Code Online (Sandbox Code Playgroud)