我想使用改造获取 JSON 数据得到此错误
Caused by: java.lang.IllegalArgumentException: URL query string "q={text}&langpair={l_from}|{l_to}" must not have replace block. For dynamic query parameters use @Query.
我的代码是
// example of my site
// http://mytempsite.com/get?q=hello friend&langpair=en|ur
@GET("get?q={text}&langpair={from}|{to}")
Call<ApiService> getJsonData(@Query("text") String text,
@Query("from") String from,
@Query("to") String to);
以及我的通话请求
Call<ApiService> call = apiService.getJsonData("hello word","en","ur");
但是当我像这样静态使用时它会起作用。
@GET("get?q=Hello Word&langpair=en|ur")
Call<ApiService> getJsonData(@Query("text") String text,
@Query("from") String from,
@Query("to") String to);
最佳答案
试试这个代码:
@GET(".")
Call<ApiService> getJsonData(@Query("q") String text,
@Query("langpair") String langpair);
Call<ApiService> call = apiService.getJsonData("hello word","en|ur");
关于java - 改进错误 URL 查询字符串在提供动态值时不得有替换 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45897750/