问题描述:

The URL https://itunes.apple.com/search?term=lennon

starts to download file.

HTTP request using HttpURLConnection and InputStream returns the json string.

It is what I need.

But how to get string response using Retrofit2?

I tryed the following code:

public interface ItunesApi {

@GET("/search")

Call<SongsGson> getData(@Query("term=") String search);

}

I send the request here:

 Retrofit retrofit = new Retrofit.Builder()

.baseUrl("https://itunes.apple.com/")

.addConverterFactory(GsonConverterFactory.create())

.build();

ItunesApi itunesApi = retrofit.create(ItunesApi.class);

itunesApi.getData(searchString).enqueue(new Callback<SongsGson>() {

@Override

public void onResponse(Call<SongsGson> call, Response<SongsGson> response) {

int resultCount = response.body().getResultCount();

}

...

}

resultCount is always equal 0.

response.isSuccessful()=true response.message()=OK

The class is below:

public class SongsGson {

@SerializedName("resultCount")

@Expose

private int resultCount;

public SongsGson(){}

public void setResultCount(int resultCount){

this.resultCount = resultCount;

}

public int getResultCount() {

return resultCount;

}

}

Any ideas, please!

相关阅读:
Top