android - 使用改造调用添加多个 @Path
问题描述
我有一个 api 请求,我需要在 url 中传递多个@Path,我这样做了,但我一直收到错误,我想在这个问题上得到一些帮助,提前谢谢你
- 这是网址示例
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
*这是我的api接口
@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>
推荐阅读
- c# - 如何检查数据库中是否有任何新数据或使用 EF Core 使用新数据更新 DbSet
- html - Visual Studio 代码搜索/替换中的正则表达式以更改具有任何结构的 url
- python-3.x - 将两个列表中包含的元素相加
- javascript - 更改对象中键的数据类型
- python-3.x - 在数据框中引入一个新列,其值基于 PySpark 中的条件
- flutter - sembast 推荐的创建商店的方法
- jmeter - JMeter 子网问题
- nuget - NuGet:正在恢复包... 已添加具有相同密钥的项目
- python - 如何仅使用 numpy 将过滤器应用于图像?
- javascript - 尝试将图像上传到 Amazon S3 但出现错误