There is such API https://api.privatbank.ua/p24api/exchange_rates?json&date=01.12.2014 using retrofit I want to get json with the specified parameters (date)

Here is my interface

public interface PrivatApi { @GET("p24api/exchange_rates") Call<List<Rate>> getSelectedData(@Query("date") String date); } 

Do I pass the date parameter correctly? my method does not work! (

  private void getRatesOnDate( ) { retrofit = new Retrofit.Builder() .baseUrl(URL) .addConverterFactory(GsonConverterFactory.create()) .build(); service = retrofit.create(PrivatApi.class); rates = new ArrayList<>(); String selectedate = "31.03.2014"; service.getSelectedData("", selectedate).enqueue(new Callback<List<Rate>>() { @Override public void onResponse(Call<List<Rate>> call, Response<List<Rate>> response) { rates.addAll(response.body()); } @Override public void onFailure(Call<List<Rate>> call, Throwable t) { Log.e("MyLog", "onFailure" + t.toString()); } }); } 
  • Throws out the error onFailurecom.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient (true) to accept malformed JSON at line 1 column 1 path $ - Denis Melnik
  • Show the code associated with the request. All the - Flippy
  • added the code in question. - Denis Melnik

2 answers 2

Try this

 public interface PrivatApi { @GET("p24api/exchange_rates") Call<List<Rate>> getSelectedData(@Query("json") String json, @Query("date") String date); } 

And so call

 getSelectedData("", date); 
  • did not help, but the error changed onFailurejava.lang.IllegalStateException: Expected BEGIN_ARRAY but it was BEGIN_OBJECT at line 1 column 2 path $ - Denis Melnik
  • Found a mistake in the file description - Denis Melnik

Try:

 public interface PrivatApi { @GET("p24api/exchange_rates") Call<String> getSelectedData(@Query("json") String json, @Query("date") String date); } 

or

 public interface PrivatApi { @GET("p24api/exchange_rates") Call<String> getSelectedData(@Query("json&date") String dateInJson); } 

if everything successfully creates an Object depending on the json answer, change the Call string to Call your_object and do not forget to include GSONBuilder in the retrofit build and visit http://www.jsonschema2pojo.org/