2014-11-24 22 views
0

我已经通过调用如何使用改造取回字符串作为响应?

String s=findDate(); 

这findDate尝试()被宣布改造服务为

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

这是正确的吗?

但我得到的响应作为字符串214-11-24当我尝试使用异步回调。为什么是这样?服务器返回日期为一个字符串,如2014-11-24

+0

请澄清你的问题。 “我得到” 是什么?并请显示您的异步改造界面。 – GreyBeardedGeek 2014-11-24 05:57:06

+0

GreyBeardedGeek,我已更新我的问题。 – 2014-11-24 06:29:51

回答

0

要使用Retrofit asynchronoisly,您必须在接口中声明方法并使用额外的回调参数作为最后一个参数。

然后改造将异步操作,并在数据可用时调用回调。

如果您没有用回调声明该方法,它将同步运行。

+0

是的,我已经尝试过使用回调,它的工作。但我想不使用回调。 – 2014-11-24 11:59:21

+0

您可以将它与回调异步一起使用,也可以在没有回调同步的情况下使用,并且您可以像预期的那样为您工作。你还在找什么? – GreyBeardedGeek 2014-11-25 00:20:24

+0

String s = findDate();它给我的改造错误。但是findDate(new Callback ){};工作中。 – 2014-11-25 04:50:04

0

我想一定是 public interface RetrofitService(){ @GET(/findDate) String findDate() }

,也许你可以共享RestAdapter对象

0

它为我工作。我使用改进:2.1.0。

API接口:

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

API调用:

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