2017-08-26 20 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

相關問題