改造错误 URL 查询字符串不能由提供的动态值替换块

Retrofit error URL query string must not have replace block by provided dynamically values

我想使用改造获取 JSON 数据得到这个错误

Caused by: java.lang.IllegalArgumentException: URL query string must not have replaced the block. For dynamic query parameters use @Query.

我的密码是

public interface ApiService {
    // this is link, WORD is dynamic string passing from activity
    // https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=WORD&format=json

        @GET("/w/api.php?action=query&list=search&srsearch={word}&format=json")
        Call<Search> getWordList(@Query({word}) String myText);
    }

还有这个

public class RetroClient { 
    private static final String ROOT_URL = "https://en.wikipedia.org/";

    private static Retrofit getRetrofitInstance() {
        return new Retrofit.Builder()
                .baseUrl(ROOT_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public static ApiService getApiService() {
        return getRetrofitInstance().create(ApiService.class);
    }
}

打电话

 Call<Search> call = apiService.getJsonData("myText");

 call.enqueue(new Callback<Search>() {
    @Override
    public void onResponse(Call<Search> call, Response<ApiService> Search) {
        //    int statusCode = response.code();
        if (response.body() != null) {
            translates = response.body().getMatches();
        }  

    }

    @Override
    public void onFailure(Call<Search> call, Throwable t) {

    }
 });

在 ApiService class 中显示错误。如何将 word 传递给 link,请

试试这个

    @GET("/w/api.php")
    Call<Search> getWordList(
       @Query("action") String action,
       @Query("list") String list,
       @Query("srsearch") String srsearch,
       @Query("format") String format);

然后这样调用

       Call<ApiService> call = apiService.getJsonData("query","search","<Word Which you want to pass>","json");