1
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(ScalarsConverterFactory.create()) //请求返回字符串,如需返回对象,需使用converter-gson
.baseUrl("http://www.baidu.com").build(); 2 DataService service = retrofit.create(DataService.class);
1 public interface DataService {
2     @GET("/")
3     Call<String> getData();
4 }
 Call<String> data = service.getData();
  //String msg=data.execute().body().toString();//同步执行

  //异步执行   data.enqueue(new Callback<String>() { @Override public void onResponse(Call<String> call, Response<String> response) { } @Override public void onFailure(Call<String> call, Throwable t) { } });

 

  • Gsoncom.squareup.retrofit2:converter-gson
  • Jacksoncom.squareup.retrofit2:converter-jackson
  • Moshicom.squareup.retrofit2:converter-moshi
  • Protobufcom.squareup.retrofit2:converter-protobuf
  • Wirecom.squareup.retrofit2:converter-wire
  • Simple XMLcom.squareup.retrofit2:converter-simplexml
  • Scalars (primitives, boxed, and String): com.squareup.retrofit2:converter-scalars
posted on 2016-08-18 10:33  向着大牛奋斗  阅读(1357)  评论(0编辑  收藏  举报