首页 > 解决方案 > 使用改造调用添加多个 @Path

问题描述

我有一个 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)
  }

 Error Unable to create call adapter for class com.dic.mydictionnary.models.DictionnaryModelItem
       for method ApiInterface.getDictionnaryWord

*这是我的api接口

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

}

标签: androidkotlinretrofit

解决方案


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

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

推荐阅读