目前,我正在使用Retrofit从api获取数据。但是数据的格式与其他格式有点不同,例如:
["tayl",["taylor swift","taylor swift kanye west","taylor swift famous","taylor swift mp3","taylor lautner","taylor swift wiki","taylor swift 1989","taylor hill","taylor swift 2016","taylor kinney"]]
所以,如果我想使用改造,我想要求解析值的最佳解决方案以获得如下所示的列表:
"taylor swift","taylor swift kanye west","taylor swift famous","taylor swift mp3","taylor lautner","taylor swift wiki","taylor swift 1989","taylor hill","taylor swift 2016","taylor kinney"
上述文件的内容是GoogleAutoComplete Api为我返回的数据,其中包含以下链接:
http://suggestqueries.google.com/complete/search?client=firefox&q=tayl
我实现了如下代码但不好:
@Headers({
"Accept: application/json",
"Content-Type: application/json; charset=UTF-8"
})
@GET("complete/search?")
Call<ResponseBody> getAutoComplete(@Query(@Query("q")String query);
以下是我正在使用的响应代码:
autoCompleteCall = googleApi.getAutoComplete(client, keyword);
autoCompleteCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response != null &&
response.body() != null) {
System.out.println(" String response======= " + response.body().toString());
return;
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
但回复给我的回复是空的。 在这种情况下请帮助我。 感谢。
答案 0 :(得分:1)
在接口中定义API端点,如下所示:
replay()
按如下方式发出网络请求:
@GET("complete/search")
Call<ResponseBody> getAutoComplete(
@Query("client") String client,
@Query("q") String query);