2017-08-26 19 views
0

我想用改造得到这个错误改造错误URL查询字符串必须没有替换块动态值

所致得到JSON数据:java.lang.IllegalArgumentException异常:URL查询字符串 “Q = {text} & langpair = {l_from} | {l_to}“不能有替换块。对于 动态查询参数使用@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); 

回答

1

试试这个代码:

@GET(".") 
Call<ApiService> getJsonData(@Query("q") String text, 
          @Query("langpair") String langpair); 

Call<ApiService> call = apiService.getJsonData("hello word","en|ur"); 
+0

感谢:错误删除,但不返回任何东西,只有空白的活动? – Attaullah

+0

而不是@GET(“。”),我使用@GET(“get?”)现在工作谢谢 – Attaullah

相关问题