使用retrofit调用添加多个@Path



我有一个api请求,在url中我需要传递多个@Path,我这样做了,但我一直得到一个错误,我想得到一些帮助与这个问题,提前感谢你

  • 这是url的示例
    https://api.site.dev/api/v2/entries/en_US/hello
    
  • 这是改造设置

@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

*这是我的apiinterface

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

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

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

最新更新