I have a website link that shows only a string like this 18.06#21.06#19.42
which continuously changes after some seconds. I tried to fetch it with Retrofit but could not fetch it like we need a Json
but the link returns a String. Now, how can I access this data into my application in form of String?
website page link: https://prdec.com/status_app/status_app_return_string.php
Error:
Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
ApiClient.java
public class ApiClient {
public static Retrofit retrofit;
public static String BASE_URL = "https://prdec.com/status_app/";
public static Retrofit getRetrofit(){
if (retrofit == null){
retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
**ApiService.java**
public interface ApiService {
@GET("status_app_return_string.php")
Call<String> getStringResponse();
}
inside **MainActivity.java**
private void getStatusResponse() {
ApiService apiService;
apiService = ApiClient.getRetrofit().create(ApiService.class);
apiService.getStringResponse().enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
Toast.makeText(MainActivity.this, response.body(), Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<String> call, Throwable t) {
Log.d(TAG, "Failed: "+ t.getMessage());
Toast.makeText(MainActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}