简体   繁体   中英

How to get back String as a response using retrofit?

i have tried by calling

String s=findDate();

this findDate() is declared in retrofit service as

public RetrofitService{
@GET(/findDate)
String findDate()
}

Is this correct?

But i am getting response as a string 214-11-24 when i tried using Async Callback. Why it is so? The server is returning date as a string like 2014-11-24

To use Retrofit asynchronoisly, you must declare the method in the interface with an extra Callback parameter as the last parameter.

Retrofit will then operate asynchronously, and invoke your Callback when the data is available.

If you do not declare the method with a Callback, it operates synchronously.

I think must be public interface RetrofitService(){ @GET(/findDate) String findDate() }

and maybe you could share the RestAdapter object

It worked for me. I use retrofit:2.1.0.

Api interface:

public interface APIService {
@GET("api/get_info")
    Call<ResponseBody> getInfo();//import okhttp3.ResponseBody;
}

Api call:

// Retrofit service creation code skipped here
String json = retrofitService().getInfo().execute().body().string();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM